Subsystems (5)
Christian König
reviewerHey Alex,
I've decided to split this patch set into two because we still can't figure out where the VCN regressions come from.
Ruijing tested them and confirmed that they don't regress VCN.
Can you and maybe Felix take a look and review them?
Thanks,
Christian.
Christian König
reviewerPATCH 1/7 drm/sched: move calling drm_sched_entity_select_rq
We already discussed that the call to drm_sched_entity_select_rq() needs to move to drm_sched_job_arm() to be able to set a new scheduler list between _init() and _arm(). This was just not applied for some reason.
--- drivers/gpu/drm/scheduler/sched_main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +1 -2
@@ -592,7 +592,6 @@ int drm_sched_job_init(struct drm_sched_job *job, struct drm_sched_entity *entity, void *owner) { -drm_sched_entity_select_rq (entity );if (!entity->rq)return -ENOENT ;
@@ -628,7 +627,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)struct drm_sched_entity *entity = job->entity;BUG_ON (!entity); - +drm_sched_entity_select_rq (entity); sched = entity->rq->sched; job->sched = sched;
Signature · 1 line
2.25.1
Christian König
reviewerPATCH 2/7 drm/amdgpu: remove SRIOV and MCBP dependencies from the CS
In reply to Christian KönigWe should not have any different CS constrains based on the execution environment.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6 -8
@@ -814,7 +814,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p)if (r)return r; -if (amdgpu_mcbp ||amdgpu_sriov_vf (adev)) { +if (fpriv->csa_va) { bo_va = fpriv->csa_va;BUG_ON (!bo_va); r =amdgpu_vm_bo_update (adev, bo_va, false);
@@ -898,13 +898,11 @@ static int amdgpu_cs_ib_fill(struct amdgpu_device *adev,continue ;if (chunk_ib->ip_type ==AMDGPU_HW_IP_GFX && - (amdgpu_mcbp ||amdgpu_sriov_vf (adev))) { -if (chunk_ib->flags &AMDGPU_IB_FLAG_PREEMPT ) { -if (chunk_ib->flags &AMDGPU_IB_FLAG_CE ) - ce_preempt++; -else - de_preempt++; - } + chunk_ib->flags &AMDGPU_IB_FLAG_PREEMPT ) { +if (chunk_ib->flags &AMDGPU_IB_FLAG_CE ) + ce_preempt++; +else + de_preempt++;/* each GFX command submit allows 0 or 1 IB preemptible for CE & DE */ if (ce_preempt >1 || de_preempt >1 )
Signature · 1 line
2.25.1
Christian König
reviewerPATCH 3/7 drm/amdgpu: move setting the job resources
In reply to Christian KönigMove setting the job resources into amdgpu_job.c
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 21 ++------------------- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 17 +++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 2 ++ 3 files changed, 21 insertions(+), 19 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +2 -19
@@ -495,9 +495,6 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,struct amdgpu_vm *vm = &fpriv->vm;struct amdgpu_bo_list_entry *e;struct list_head duplicates; -struct amdgpu_bo *gds; -struct amdgpu_bo *gws; -struct amdgpu_bo *oa;int r;INIT_LIST_HEAD (&p->validated);
@@ -614,22 +611,8 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,amdgpu_cs_report_moved_bytes (p->adev, p->bytes_moved, p->bytes_moved_vis); - gds = p->bo_list->gds_obj; - gws = p->bo_list->gws_obj; - oa = p->bo_list->oa_obj; - -if (gds) { - p->job->gds_base =amdgpu_bo_gpu_offset (gds) >>PAGE_SHIFT ; - p->job->gds_size =amdgpu_bo_size (gds) >>PAGE_SHIFT ; - } -if (gws) { - p->job->gws_base =amdgpu_bo_gpu_offset (gws) >>PAGE_SHIFT ; - p->job->gws_size =amdgpu_bo_size (gws) >>PAGE_SHIFT ; - } -if (oa) { - p->job->oa_base =amdgpu_bo_gpu_offset (oa) >>PAGE_SHIFT ; - p->job->oa_size =amdgpu_bo_size (oa) >>PAGE_SHIFT ; - } +amdgpu_job_set_resources (p->job, p->bo_list->gds_obj, + p->bo_list->gws_obj, p->bo_list->oa_obj);if (!r && p->uf_entry.tv.bo) {struct amdgpu_bo *uf =ttm_to_amdgpu_bo (p->uf_entry.tv.bo);
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +17 -0
@@ -132,6 +132,23 @@ int amdgpu_job_alloc_with_ib(struct amdgpu_device *adev, unsigned size,return r; } +void amdgpu_job_set_resources (struct amdgpu_job *job,struct amdgpu_bo *gds, +struct amdgpu_bo *gws,struct amdgpu_bo *oa) +{ +if (gds) { + job->gds_base =amdgpu_bo_gpu_offset (gds) >>PAGE_SHIFT ; + job->gds_size =amdgpu_bo_size (gds) >>PAGE_SHIFT ; + } +if (gws) { + job->gws_base =amdgpu_bo_gpu_offset (gws) >>PAGE_SHIFT ; + job->gws_size =amdgpu_bo_size (gws) >>PAGE_SHIFT ; + } +if (oa) { + job->oa_base =amdgpu_bo_gpu_offset (oa) >>PAGE_SHIFT ; + job->oa_size =amdgpu_bo_size (oa) >>PAGE_SHIFT ; + } +} +void amdgpu_job_free_resources (struct amdgpu_job *job) {struct amdgpu_ring *ring =to_amdgpu_ring (job->base.sched);
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +2 -0
@@ -76,6 +76,8 @@ int amdgpu_job_alloc(struct amdgpu_device *adev, unsigned num_ibs, struct amdgpu_job **job, struct amdgpu_vm *vm);int amdgpu_job_alloc_with_ib (struct amdgpu_device *adev,unsigned size,enum amdgpu_ib_pool_type pool,struct amdgpu_job **job); +void amdgpu_job_set_resources (struct amdgpu_job *job,struct amdgpu_bo *gds, +struct amdgpu_bo *gws,struct amdgpu_bo *oa);void amdgpu_job_free_resources (struct amdgpu_job *job);void amdgpu_job_free (struct amdgpu_job *job); int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
Signature · 1 line
2.25.1
Christian König
reviewerPATCH 4/7 drm/amdgpu: revert "partial revert "remove ctx->lock" v2"
In reply to Christian KönigThis reverts commit 94f4c4965e5513ba624488f4b601d6b385635aec.
We found that the bo_list is missing a protection for its list entries. Since that is fixed now this workaround can be removed again.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 21 ++++++--------------- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 2 -- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h | 1 - 3 files changed, 6 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +6 -15
@@ -128,8 +128,6 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs goto free_chunk; } -mutex_lock (&p->ctx->lock); -/* skip guilty context job */ if (atomic_read (&p->ctx->guilty) ==1 ) { ret = -ECANCELED ;
@@ -691,7 +689,6 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser, int error,dma_fence_put (parser->fence);if (parser->ctx) { -mutex_unlock (&parser->ctx->lock);amdgpu_ctx_put (parser->ctx); }if (parser->bo_list)
@@ -1138,9 +1135,6 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev, {int i, r; -/* TODO: Investigate why we still need the context lock */ -mutex_unlock (&p->ctx->lock); -for (i =0 ; i < p->nchunks; ++i) {struct amdgpu_cs_chunk *chunk;
@@ -1151,34 +1145,32 @@ static int amdgpu_cs_dependencies(struct amdgpu_device *adev,case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES : r =amdgpu_cs_process_fence_dep (p, chunk);if (r) - goto out; +return r;break ;case AMDGPU_CHUNK_ID_SYNCOBJ_IN : r =amdgpu_cs_process_syncobj_in_dep (p, chunk);if (r) - goto out; +return r;break ;case AMDGPU_CHUNK_ID_SYNCOBJ_OUT : r =amdgpu_cs_process_syncobj_out_dep (p, chunk);if (r) - goto out; +return r;break ;case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT : r =amdgpu_cs_process_syncobj_timeline_in_dep (p, chunk);if (r) - goto out; +return r;break ;case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL : r =amdgpu_cs_process_syncobj_timeline_out_dep (p, chunk);if (r) - goto out; +return r;break ; } } -out: -mutex_lock (&p->ctx->lock); -return r; +return 0 ; }static void amdgpu_cs_post_dependencies (struct amdgpu_cs_parser *p)
@@ -1340,7 +1332,6 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) goto out; r =amdgpu_cs_submit (&parser, cs); - out:amdgpu_cs_parser_fini (&parser, r, reserved_buffers);
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +0 -2
@@ -315,7 +315,6 @@ static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority,kref_init (&ctx->refcount); ctx->mgr = mgr;spin_lock_init (&ctx->ring_lock); -mutex_init (&ctx->lock); ctx->reset_counter =atomic_read (&mgr->adev->gpu_reset_counter); ctx->reset_counter_query = ctx->reset_counter;
@@ -407,7 +406,6 @@ static void amdgpu_ctx_fini(struct kref *ref)drm_dev_exit (idx); } -mutex_destroy (&ctx->lock);kfree (ctx); }
drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.h +0 -1
@@ -53,7 +53,6 @@ struct amdgpu_ctx {bool preamble_presented;int32_t init_priority;int32_t override_priority; -struct mutex lock;atomic_t guilty;unsigned long ras_counter_ce;unsigned long ras_counter_ue;
Signature · 1 line
2.25.1
Christian König
reviewerPATCH 5/7 drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2
In reply to Christian KönigUse DMA_RESV_USAGE_BOOKKEEP for VM page table updates and KFD preemption fence.
v2: actually update all usages for KFD
--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 26 ++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 3 ++- 2 files changed, 18 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +16 -10
@@ -298,7 +298,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,*/ replacement =dma_fence_get_stub ();dma_resv_replace_fences (bo->tbo.base.resv, ef->base.context, - replacement,DMA_RESV_USAGE_READ ); + replacement,DMA_RESV_USAGE_BOOKKEEP );dma_fence_put (replacement);return 0 ; }
@@ -1391,8 +1391,9 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, ret =dma_resv_reserve_fences (vm->root.bo->tbo.base.resv,1 );if (ret) goto reserve_shared_fail; -amdgpu_bo_fence (vm->root.bo, - &vm->process_info->eviction_fence->base, true); +dma_resv_add_fence (vm->root.bo->tbo.base.resv, + &vm->process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP );amdgpu_bo_unreserve (vm->root.bo);/* Update process info */
@@ -1989,9 +1990,9 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( }if (!amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) && !bo->tbo.pin_count) -amdgpu_bo_fence (bo, - &avm->process_info->eviction_fence->base, - true); +dma_resv_add_fence (bo->tbo.base.resv, + &avm->process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP ); ret =unreserve_bo_and_vms (&ctx, false, false); goto out;
@@ -2760,15 +2761,18 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)if (mem->bo->tbo.pin_count)continue ; -amdgpu_bo_fence (mem->bo, - &process_info->eviction_fence->base, true); +dma_resv_add_fence (mem->bo->tbo.base.resv, + &process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP ); }/* Attach eviction fence to PD / PT BOs */ list_for_each_entry (peer_vm, &process_info->vm_list_head, vm_list_node) {struct amdgpu_bo *bo = peer_vm->root.bo; -amdgpu_bo_fence (bo, &process_info->eviction_fence->base, true); +dma_resv_add_fence (bo->tbo.base.resv, + &process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP ); } validate_map_fail:
@@ -2822,7 +2826,9 @@ int amdgpu_amdkfd_add_gws_to_process(void *info, void *gws, struct kgd_mem **mem ret =dma_resv_reserve_fences (gws_bo->tbo.base.resv,1 );if (ret) goto reserve_shared_fail; -amdgpu_bo_fence (gws_bo, &process_info->eviction_fence->base, true); +dma_resv_add_fence (gws_bo->tbo.base.resv, + &process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP );amdgpu_bo_unreserve (gws_bo);mutex_unlock (&(*mem)->process_info->lock);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +2 -1
@@ -112,7 +112,8 @@ static int amdgpu_vm_sdma_commit(struct amdgpu_vm_update_params *p,swap (p->vm->last_unlocked, tmp);dma_fence_put (tmp); }else { -amdgpu_bo_fence (p->vm->root.bo, f, true); +dma_resv_add_fence (p->vm->root.bo->tbo.base.resv, f, +DMA_RESV_USAGE_BOOKKEEP ); }if (fence && !p->immediate)
Signature · 1 line
2.25.1
Felix Kuehling
maintainerRe: [PATCH 5/7] drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2
Am 2022-09-12 um 08:36 schrieb Christian König:
Quoted 36 lines
Use
DMA_RESV_USAGE_BOOKKEEPfor VM page table updates and KFD preemption fence.v2: actually update all usages for KFD
Signed-off-by Christian König <[email protected]>--- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 26 ++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 3 ++- 2 files changed, 18 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4
-3@@ -298,7 +298,7 @@ static int amdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo,*/ replacement =dma_fence_get_stub ();dma_resv_replace_fences (bo->tbo.base.resv, ef->base.context, - replacement,DMA_RESV_USAGE_READ ); + replacement,DMA_RESV_USAGE_BOOKKEEP );dma_fence_put (replacement);return 0 ; }@@ -1391,8 +1391,9 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info, ret =dma_resv_reserve_fences (vm->root.bo->tbo.base.resv,1 );if (ret) goto reserve_shared_fail; -amdgpu_bo_fence (vm->root.bo, - &vm->process_info->eviction_fence->base, true); +dma_resv_add_fence (vm->root.bo->tbo.base.resv, + &vm->process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP );amdgpu_bo_unreserve (vm->root.bo);/* Update process info */
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( · line 1995
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-3@@ -1989,9 +1990,9 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( }if (!amdgpu_ttm_tt_get_usermm (bo->tbo.ttm) && !bo->tbo.pin_count) -amdgpu_bo_fence (bo, - &avm->process_info->eviction_fence->base, - true); +dma_resv_add_fence (bo->tbo.base.resv, + &avm->process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP );
This removes the implicit dma_resv_reserve_fences that amdgpu_bo_fence used to do. Do we need to add back an explicit dma_resv_reserve_fences somewhere here?
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) · line 2766
Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-2ret =unreserve_bo_and_vms (&ctx, false, false); goto out;@@ -2760,15 +2761,18 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef)if (mem->bo->tbo.pin_count)continue ; -amdgpu_bo_fence (mem->bo, - &process_info->eviction_fence->base, true); +dma_resv_add_fence (mem->bo->tbo.base.resv, + &process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP );
Same as above.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) · line 2775
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-1}/* Attach eviction fence to PD / PT BOs */ list_for_each_entry (peer_vm, &process_info->vm_list_head, vm_list_node) {struct amdgpu_bo *bo = peer_vm->root.bo; -amdgpu_bo_fence (bo, &process_info->eviction_fence->base, true); +dma_resv_add_fence (bo->tbo.base.resv, + &process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP );
Same as above.
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-1} validate_map_fail:@@ -2822,7 +2826,9 @@ int amdgpu_amdkfd_add_gws_to_process(void *info, void *gws, struct kgd_mem **mem ret =dma_resv_reserve_fences (gws_bo->tbo.base.resv,1 );if (ret) goto reserve_shared_fail; -amdgpu_bo_fence (gws_bo, &process_info->eviction_fence->base, true); +dma_resv_add_fence (gws_bo->tbo.base.resv, + &process_info->eviction_fence->base, +DMA_RESV_USAGE_BOOKKEEP );amdgpu_bo_unreserve (gws_bo);mutex_unlock (&(*mem)->process_info->lock);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_commit(struct amdgpu_vm_update_params *p, · line 116
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +2
-1@@ -112,7 +112,8 @@ static int amdgpu_vm_sdma_commit(struct amdgpu_vm_update_params *p,swap (p->vm->last_unlocked, tmp);dma_fence_put (tmp); }else { -amdgpu_bo_fence (p->vm->root.bo, f, true); +dma_resv_add_fence (p->vm->root.bo->tbo.base.resv, f, +DMA_RESV_USAGE_BOOKKEEP );
Same as above.
Regards,
Felix
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +0
-0}if (fence && !p->immediate)
Christian König
maintainerRe: [PATCH 5/7] drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2
Am 13.09.22 um 22:52 schrieb Felix Kuehling:
Quoted 40 lines
Am 2022-09-12 um 08:36 schrieb Christian König:
Quoted 39 lines
Use
DMA_RESV_USAGE_BOOKKEEPfor VM page table updates and KFD preemption fence.v2: actually update all usages for KFD
Signed-off-by Christian König <[email protected]>---
.../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 26 ++++++++++++------- drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c | 3 ++-2 files changed, 18 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1
-1@@ -298,7 +298,7 @@ static intamdgpu_amdkfd_remove_eviction_fence(struct amdgpu_bo *bo, */ replacement = dma_fence_get_stub(); dma_resv_replace_fences(bo->tbo.base.resv, ef->base.context, - replacement, DMA_RESV_USAGE_READ); + replacement, DMA_RESV_USAGE_BOOKKEEP); dma_fence_put(replacement); return 0;}
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-2@@ -1391,8 +1391,9 @@ static int init_kfd_vm(struct amdgpu_vm *vm,void **process_info, ret = dma_resv_reserve_fences(vm->root.bo->tbo.base.resv, 1); if (ret) goto reserve_shared_fail; - amdgpu_bo_fence(vm->root.bo, - &vm->process_info->eviction_fence->base, true); + dma_resv_add_fence(vm->root.bo->tbo.base.resv, + &vm->process_info->eviction_fence->base, + DMA_RESV_USAGE_BOOKKEEP); amdgpu_bo_unreserve(vm->root.bo); /* Update process info */@@ -1989,9 +1990,9 @@ int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( } if (!amdgpu_ttm_tt_get_usermm(bo->tbo.ttm) && !bo->tbo.pin_count)
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_map_memory_to_gpu( · line 1995
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-3- amdgpu_bo_fence(bo, - &avm->process_info->eviction_fence->base, - true); + dma_resv_add_fence(bo->tbo.base.resv, + &avm->process_info->eviction_fence->base, + DMA_RESV_USAGE_BOOKKEEP);This removes the implicit
dma_resv_reserve_fencesthatamdgpu_bo_fenceused to do. Do we need to add back an explicitdma_resv_reserve_fencessomewhere here?
I was pondering the same thought. The extra reserve in amdgpu_bo_fence() is actually just a workaround. So when this here goes boom we really need to fix it in the KFD code.
Quoted 49 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int · line 2767
Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-1ret = unreserve_bo_and_vms(&ctx, false, false); goto out;@@ -2760,15 +2761,18 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) if (mem->bo->tbo.pin_count) continue; - amdgpu_bo_fence(mem->bo, - &process_info->eviction_fence->base, true); + dma_resv_add_fence(mem->bo->tbo.base.resv, + &process_info->eviction_fence->base, + DMA_RESV_USAGE_BOOKKEEP);Same as above.
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct dma_fence **ef) · line 2775
Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-0} /* Attach eviction fence to PD / PT BOs */ list_for_each_entry(peer_vm, &process_info->vm_list_head, vm_list_node) { struct amdgpu_bo *bo = peer_vm->root.bo; - amdgpu_bo_fence(bo, &process_info->eviction_fence->base, true); + dma_resv_add_fence(bo->tbo.base.resv, + &process_info->eviction_fence->base, + DMA_RESV_USAGE_BOOKKEEP);Same as above.
Quoted 19 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0
-0}
validate_map_fail:drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +3
-1@@ -2822,7 +2826,9 @@ int amdgpu_amdkfd_add_gws_to_process(void *info, void *gws, struct kgd_mem **mem ret = dma_resv_reserve_fences(gws_bo->tbo.base.resv, 1); if (ret) goto reserve_shared_fail; - amdgpu_bo_fence(gws_bo, &process_info->eviction_fence->base, true); + dma_resv_add_fence(gws_bo->tbo.base.resv, + &process_info->eviction_fence->base, + DMA_RESV_USAGE_BOOKKEEP); amdgpu_bo_unreserve(gws_bo); mutex_unlock(&(*mem)->process_info->lock);diff --git
a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.cb/drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.cindex1fd3cbca20a2..03ec099d64e0100644drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +0
-0@@ -112,7 +112,8 @@ static int amdgpu_vm_sdma_commit(struct amdgpu_vm_update_params *p,
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c static int amdgpu_vm_sdma_commit(struct amdgpu_vm_update_params *p, · line 116
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +2
-1swap(p->vm->last_unlocked, tmp); dma_fence_put(tmp); } else { - amdgpu_bo_fence(p->vm->root.bo, f, true); +dma_resv_add_fence (p->vm->root.bo->tbo.base.resv, f, + DMA_RESV_USAGE_BOOKKEEP);Same as above.
This one here should certainly have an associated dma_fence_reserve_fence().
Regards,
Christian.
Quoted 7 lines
Regards,
FelixQuoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm_sdma.c +0
-0} if (fence && !p->immediate)
Christian König
reviewerPATCH 6/7 drm/amdgpu: cleanup CS init/fini and pass1
In reply to Christian KönigCleanup the coding style and function names to represent the data they process. Only initialize and cleanup the CS structure in init/fini.
Check the size of the IB chunk in pass1.
v2: fix job initialisation order and use correct scheduler instance
v3: try to move all functional changes into a separate patch.
v4: move reordering and pass2 out of this patch as well
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 197 +++++++++++++------------ 1 file changed, 104 insertions(+), 93 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +104 -93
@@ -39,9 +39,42 @@#include "amdgpu_gem.h" #include "amdgpu_ras.h" -static int amdgpu_cs_user_fence_chunk (struct amdgpu_cs_parser *p, -struct drm_amdgpu_cs_chunk_fence *data, -uint32_t *offset) +static int amdgpu_cs_parser_init (struct amdgpu_cs_parser *p, +struct amdgpu_device *adev, +struct drm_file *filp, +union drm_amdgpu_cs *cs) +{ +struct amdgpu_fpriv *fpriv = filp->driver_priv; + +if (cs->in.num_chunks ==0 ) +return -EINVAL ; + +memset (p,0 ,sizeof (*p)); + p->adev = adev; + p->filp = filp; + + p->ctx =amdgpu_ctx_get (fpriv, cs->in.ctx_id); +if (!p->ctx) +return -EINVAL ; + +if (atomic_read (&p->ctx->guilty)) { +amdgpu_ctx_put (p->ctx); +return -ECANCELED ; + } +return 0 ; +} + +static int amdgpu_cs_p1_ib (struct amdgpu_cs_parser *p, +struct drm_amdgpu_cs_chunk_ib *chunk_ib, +unsigned int *num_ibs) +{ + ++(*num_ibs); +return 0 ; +} + +static int amdgpu_cs_p1_user_fence (struct amdgpu_cs_parser *p, +struct drm_amdgpu_cs_chunk_fence *data, +uint32_t *offset) {struct drm_gem_object *gobj;struct amdgpu_bo *bo;
@@ -80,11 +113,11 @@ static int amdgpu_cs_user_fence_chunk(struct amdgpu_cs_parser *p,return r; } -static int amdgpu_cs_bo_handles_chunk (struct amdgpu_cs_parser *p, -struct drm_amdgpu_bo_list_in *data) +static int amdgpu_cs_p1_bo_handles (struct amdgpu_cs_parser *p, +struct drm_amdgpu_bo_list_in *data) { +struct drm_amdgpu_bo_list_entry *info;int r; -struct drm_amdgpu_bo_list_entry *info =NULL ; r =amdgpu_bo_create_list_entry_array (data, &info);if (r)
@@ -104,7 +137,9 @@ static int amdgpu_cs_bo_handles_chunk(struct amdgpu_cs_parser *p,return r; } -static int amdgpu_cs_parser_init (struct amdgpu_cs_parser *p,union drm_amdgpu_cs *cs) +/* Copy the data from userspace and go over it the first time */ +static int amdgpu_cs_pass1 (struct amdgpu_cs_parser *p, +union drm_amdgpu_cs *cs) {struct amdgpu_fpriv *fpriv = p->filp->driver_priv;struct amdgpu_vm *vm = &fpriv->vm;
@@ -112,28 +147,14 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_csuint64_t *chunk_array;unsigned size, num_ibs =0 ;uint32_t uf_offset =0 ; -int i;int ret; +int i; -if (cs->in.num_chunks ==0 ) -return -EINVAL ; - - chunk_array =kvmalloc_array (cs->in.num_chunks,sizeof (uint64_t ),GFP_KERNEL ); + chunk_array =kvmalloc_array (cs->in.num_chunks,sizeof (uint64_t ), +GFP_KERNEL );if (!chunk_array)return -ENOMEM ; - p->ctx =amdgpu_ctx_get (fpriv, cs->in.ctx_id); -if (!p->ctx) { - ret = -EINVAL ; - goto free_chunk; - } - -/* skip guilty context job */ -if (atomic_read (&p->ctx->guilty) ==1 ) { - ret = -ECANCELED ; - goto free_chunk; - } -/* get chunks */ chunk_array_user =u64_to_user_ptr (cs->in.chunks); if (copy_from_user(chunk_array, chunk_array_user,
@@ -168,7 +189,8 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs size = p->chunks[i].length_dw; cdata =u64_to_user_ptr (user_chunk.chunk_data); - p->chunks[i].kdata =kvmalloc_array (size,sizeof (uint32_t ),GFP_KERNEL ); + p->chunks[i].kdata =kvmalloc_array (size,sizeof (uint32_t ), +GFP_KERNEL );if (p->chunks[i].kdata ==NULL ) { ret = -ENOMEM ; i--;
@@ -180,36 +202,35 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_cs goto free_partial_kdata; } +/* Assume the worst on the following checks */ + ret = -EINVAL ;switch (p->chunks[i].chunk_id) {case AMDGPU_CHUNK_ID_IB : - ++num_ibs; +if (size <sizeof (struct drm_amdgpu_cs_chunk_ib )) + goto free_partial_kdata; + + ret =amdgpu_cs_p1_ib (p, p->chunks[i].kdata, &num_ibs); +if (ret) + goto free_partial_kdata;break ;case AMDGPU_CHUNK_ID_FENCE : - size =sizeof (struct drm_amdgpu_cs_chunk_fence ); -if (p->chunks[i].length_dw *sizeof (uint32_t ) < size) { - ret = -EINVAL ; +if (size <sizeof (struct drm_amdgpu_cs_chunk_fence )) goto free_partial_kdata; - } - ret =amdgpu_cs_user_fence_chunk (p, p->chunks[i].kdata, - &uf_offset); + ret =amdgpu_cs_p1_user_fence (p, p->chunks[i].kdata, + &uf_offset);if (ret) goto free_partial_kdata; -break ;case AMDGPU_CHUNK_ID_BO_HANDLES : - size =sizeof (struct drm_amdgpu_bo_list_in ); -if (p->chunks[i].length_dw *sizeof (uint32_t ) < size) { - ret = -EINVAL ; +if (size <sizeof (struct drm_amdgpu_bo_list_in )) goto free_partial_kdata; - } - ret =amdgpu_cs_bo_handles_chunk (p, p->chunks[i].kdata); + ret =amdgpu_cs_p1_bo_handles (p, p->chunks[i].kdata);if (ret) goto free_partial_kdata; -break ;case AMDGPU_CHUNK_ID_DEPENDENCIES :
@@ -221,7 +242,6 @@ static int amdgpu_cs_parser_init(struct amdgpu_cs_parser *p, union drm_amdgpu_csbreak ;default : - ret = -EINVAL ; goto free_partial_kdata; } }
@@ -660,52 +680,6 @@ static int amdgpu_cs_sync_rings(struct amdgpu_cs_parser *p)return 0 ; } -/** -* amdgpu_cs_parser_fini() - clean parser states -* @parser: parser structure holding parsing context. -* @error: error number -* @backoff: indicator to backoff the reservation -* -* If error is set then unvalidate buffer, otherwise just free memory -* used by parsing context. -**/ -static void amdgpu_cs_parser_fini (struct amdgpu_cs_parser *parser,int error, -bool backoff) -{ -unsigned i; - -if (error && backoff) { -ttm_eu_backoff_reservation (&parser->ticket, - &parser->validated); -mutex_unlock (&parser->bo_list->bo_list_mutex); - } - -for (i =0 ; i < parser->num_post_deps; i++) { -drm_syncobj_put (parser->post_deps[i].syncobj); -kfree (parser->post_deps[i].chain); - } -kfree (parser->post_deps); - -dma_fence_put (parser->fence); - -if (parser->ctx) { -amdgpu_ctx_put (parser->ctx); - } -if (parser->bo_list) -amdgpu_bo_list_put (parser->bo_list); - -for (i =0 ; i < parser->nchunks; i++) -kvfree (parser->chunks[i].kdata); -kvfree (parser->chunks); -if (parser->job) -amdgpu_job_free (parser->job); -if (parser->uf_entry.tv.bo) { -struct amdgpu_bo *uf =ttm_to_amdgpu_bo (parser->uf_entry.tv.bo); - -amdgpu_bo_unref (&uf); - } -} -static int amdgpu_cs_vm_handling (struct amdgpu_cs_parser *p) {struct amdgpu_ring *ring =to_amdgpu_ring (p->entity->rq->sched);
@@ -1280,11 +1254,47 @@ static void trace_amdgpu_cs_ibs(struct amdgpu_cs_parser *parser)trace_amdgpu_cs (parser, i); } +/* Cleanup the parser structure */ +static void amdgpu_cs_parser_fini (struct amdgpu_cs_parser *parser,int error, +bool backoff) +{ +unsigned i; + +if (error && backoff) { +ttm_eu_backoff_reservation (&parser->ticket, + &parser->validated); +mutex_unlock (&parser->bo_list->bo_list_mutex); + } + +for (i =0 ; i < parser->num_post_deps; i++) { +drm_syncobj_put (parser->post_deps[i].syncobj); +kfree (parser->post_deps[i].chain); + } +kfree (parser->post_deps); + +dma_fence_put (parser->fence); + +if (parser->ctx) +amdgpu_ctx_put (parser->ctx); +if (parser->bo_list) +amdgpu_bo_list_put (parser->bo_list); + +for (i =0 ; i < parser->nchunks; i++) +kvfree (parser->chunks[i].kdata); +kvfree (parser->chunks); +if (parser->job) +amdgpu_job_free (parser->job); +if (parser->uf_entry.tv.bo) { +struct amdgpu_bo *uf =ttm_to_amdgpu_bo (parser->uf_entry.tv.bo); + +amdgpu_bo_unref (&uf); + } +} +int amdgpu_cs_ioctl (struct drm_device *dev,void *data,struct drm_file *filp) {struct amdgpu_device *adev =drm_to_adev (dev); -union drm_amdgpu_cs *cs = data; -struct amdgpu_cs_parser parser = {}; +struct amdgpu_cs_parser parser;bool reserved_buffers = false;int r;
@@ -1294,16 +1304,17 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)if (!adev->accel_working)return -EBUSY ; - parser.adev = adev; - parser.filp = filp; - - r =amdgpu_cs_parser_init (&parser, data); + r =amdgpu_cs_parser_init (&parser, adev, filp, data);if (r) {if (printk_ratelimit ())DRM_ERROR ("Failed to initialize parser %d!\n" , r); goto out; } + r =amdgpu_cs_pass1 (&parser, data); +if (r) + goto out; + r =amdgpu_cs_ib_fill (adev, &parser);if (r) goto out;
@@ -1331,7 +1342,7 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)if (r) goto out; - r =amdgpu_cs_submit (&parser, cs); + r =amdgpu_cs_submit (&parser, data); out:amdgpu_cs_parser_fini (&parser, r, reserved_buffers);
Signature · 1 line
2.25.1
Christian König
reviewerPATCH 7/7 drm/amdgpu: reorder CS code
In reply to Christian KönigSort the functions in the order they are called
--- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 802 +++++++++++++------------ 1 file changed, 402 insertions(+), 400 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +402 -400
@@ -278,6 +278,323 @@ static int amdgpu_cs_pass1(struct amdgpu_cs_parser *p,return ret; } +static int amdgpu_cs_ib_fill (struct amdgpu_device *adev, +struct amdgpu_cs_parser *parser) +{ +struct amdgpu_fpriv *fpriv = parser->filp->driver_priv; +struct amdgpu_vm *vm = &fpriv->vm; +int r, ce_preempt =0 , de_preempt =0 ; +struct amdgpu_ring *ring; +int i, j; + +for (i =0 , j =0 ; i < parser->nchunks && j < parser->job->num_ibs; i++) { +struct amdgpu_cs_chunk *chunk; +struct amdgpu_ib *ib; +struct drm_amdgpu_cs_chunk_ib *chunk_ib; +struct drm_sched_entity *entity; + + chunk = &parser->chunks[i]; + ib = &parser->job->ibs[j]; + chunk_ib = (struct drm_amdgpu_cs_chunk_ib *)chunk->kdata; + +if (chunk->chunk_id !=AMDGPU_CHUNK_ID_IB ) +continue ; + +if (chunk_ib->ip_type ==AMDGPU_HW_IP_GFX && + chunk_ib->flags &AMDGPU_IB_FLAG_PREEMPT ) { +if (chunk_ib->flags &AMDGPU_IB_FLAG_CE ) + ce_preempt++; +else + de_preempt++; + +/* each GFX command submit allows 0 or 1 IB preemptible for CE & DE */ +if (ce_preempt >1 || de_preempt >1 ) +return -EINVAL ; + } + + r =amdgpu_ctx_get_entity (parser->ctx, chunk_ib->ip_type, + chunk_ib->ip_instance, chunk_ib->ring, + &entity); +if (r) +return r; + +if (chunk_ib->flags &AMDGPU_IB_FLAG_PREAMBLE ) + parser->job->preamble_status |= +AMDGPU_PREAMBLE_IB_PRESENT ; + +if (parser->entity && parser->entity != entity) +return -EINVAL ; + +/* Return if there is no run queue associated with this entity. +* Possibly because of disabled HW IP*/ +if (entity->rq ==NULL ) +return -EINVAL ; + + parser->entity = entity; + + ring =to_amdgpu_ring (entity->rq->sched); + r =amdgpu_ib_get (adev, vm, ring->funcs->parse_cs ? + chunk_ib->ib_bytes :0 , +AMDGPU_IB_POOL_DELAYED , ib); +if (r) { +DRM_ERROR ("Failed to get ib !\n" ); +return r; + } + + ib->gpu_addr = chunk_ib->va_start; + ib->length_dw = chunk_ib->ib_bytes /4 ; + ib->flags = chunk_ib->flags; + + j++; + } + +/* MM engine doesn't support user fences */ + ring =to_amdgpu_ring (parser->entity->rq->sched); +if (parser->job->uf_addr && ring->funcs->no_user_fence) +return -EINVAL ; + +return 0 ; +} + +static int amdgpu_cs_process_fence_dep (struct amdgpu_cs_parser *p, +struct amdgpu_cs_chunk *chunk) +{ +struct amdgpu_fpriv *fpriv = p->filp->driver_priv; +unsigned num_deps; +int i, r; +struct drm_amdgpu_cs_chunk_dep *deps; + + deps = (struct drm_amdgpu_cs_chunk_dep *)chunk->kdata; + num_deps = chunk->length_dw *4 / +sizeof (struct drm_amdgpu_cs_chunk_dep ); + +for (i =0 ; i < num_deps; ++i) { +struct amdgpu_ctx *ctx; +struct drm_sched_entity *entity; +struct dma_fence *fence; + + ctx =amdgpu_ctx_get (fpriv, deps[i].ctx_id); +if (ctx ==NULL ) +return -EINVAL ; + + r =amdgpu_ctx_get_entity (ctx, deps[i].ip_type, + deps[i].ip_instance, + deps[i].ring, &entity); +if (r) { +amdgpu_ctx_put (ctx); +return r; + } + + fence =amdgpu_ctx_get_fence (ctx, entity, deps[i].handle); +amdgpu_ctx_put (ctx); + +if (IS_ERR (fence)) +return PTR_ERR (fence); +else if (!fence) +continue ; + +if (chunk->chunk_id ==AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES ) { +struct drm_sched_fence *s_fence; +struct dma_fence *old = fence; + + s_fence =to_drm_sched_fence (fence); + fence =dma_fence_get (&s_fence->scheduled); +dma_fence_put (old); + } + + r =amdgpu_sync_fence (&p->job->sync, fence); +dma_fence_put (fence); +if (r) +return r; + } +return 0 ; +} + +static int amdgpu_syncobj_lookup_and_add_to_sync (struct amdgpu_cs_parser *p, +uint32_t handle,u64 point, +u64 flags) +{ +struct dma_fence *fence; +int r; + + r =drm_syncobj_find_fence (p->filp, handle, point, flags, &fence); +if (r) { +DRM_ERROR ("syncobj %u failed to find fence @ %llu (%d)!\n" , + handle, point, r); +return r; + } + + r =amdgpu_sync_fence (&p->job->sync, fence); +dma_fence_put (fence); + +return r; +} + +static int amdgpu_cs_process_syncobj_in_dep (struct amdgpu_cs_parser *p, +struct amdgpu_cs_chunk *chunk) +{ +struct drm_amdgpu_cs_chunk_sem *deps; +unsigned num_deps; +int i, r; + + deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata; + num_deps = chunk->length_dw *4 / +sizeof (struct drm_amdgpu_cs_chunk_sem ); +for (i =0 ; i < num_deps; ++i) { + r =amdgpu_syncobj_lookup_and_add_to_sync (p, deps[i].handle, +0 ,0 ); +if (r) +return r; + } + +return 0 ; +} + +static int amdgpu_cs_process_syncobj_timeline_in_dep (struct amdgpu_cs_parser *p, +struct amdgpu_cs_chunk *chunk) +{ +struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps; +unsigned num_deps; +int i, r; + + syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata; + num_deps = chunk->length_dw *4 / +sizeof (struct drm_amdgpu_cs_chunk_syncobj ); +for (i =0 ; i < num_deps; ++i) { + r =amdgpu_syncobj_lookup_and_add_to_sync (p, + syncobj_deps[i].handle, + syncobj_deps[i].point, + syncobj_deps[i].flags); +if (r) +return r; + } + +return 0 ; +} + +static int amdgpu_cs_process_syncobj_out_dep (struct amdgpu_cs_parser *p, +struct amdgpu_cs_chunk *chunk) +{ +struct drm_amdgpu_cs_chunk_sem *deps; +unsigned num_deps; +int i; + + deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata; + num_deps = chunk->length_dw *4 / +sizeof (struct drm_amdgpu_cs_chunk_sem ); + +if (p->post_deps) +return -EINVAL ; + + p->post_deps =kmalloc_array (num_deps,sizeof (*p->post_deps), +GFP_KERNEL ); + p->num_post_deps =0 ; + +if (!p->post_deps) +return -ENOMEM ; + + +for (i =0 ; i < num_deps; ++i) { + p->post_deps[i].syncobj = +drm_syncobj_find (p->filp, deps[i].handle); +if (!p->post_deps[i].syncobj) +return -EINVAL ; + p->post_deps[i].chain =NULL ; + p->post_deps[i].point =0 ; + p->num_post_deps++; + } + +return 0 ; +} + + +static int amdgpu_cs_process_syncobj_timeline_out_dep (struct amdgpu_cs_parser *p, +struct amdgpu_cs_chunk *chunk) +{ +struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps; +unsigned num_deps; +int i; + + syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata; + num_deps = chunk->length_dw *4 / +sizeof (struct drm_amdgpu_cs_chunk_syncobj ); + +if (p->post_deps) +return -EINVAL ; + + p->post_deps =kmalloc_array (num_deps,sizeof (*p->post_deps), +GFP_KERNEL ); + p->num_post_deps =0 ; + +if (!p->post_deps) +return -ENOMEM ; + +for (i =0 ; i < num_deps; ++i) { +struct amdgpu_cs_post_dep *dep = &p->post_deps[i]; + + dep->chain =NULL ; +if (syncobj_deps[i].point) { + dep->chain =dma_fence_chain_alloc (); +if (!dep->chain) +return -ENOMEM ; + } + + dep->syncobj =drm_syncobj_find (p->filp, + syncobj_deps[i].handle); +if (!dep->syncobj) { +dma_fence_chain_free (dep->chain); +return -EINVAL ; + } + dep->point = syncobj_deps[i].point; + p->num_post_deps++; + } + +return 0 ; +} + +static int amdgpu_cs_dependencies (struct amdgpu_device *adev, +struct amdgpu_cs_parser *p) +{ +int i, r; + +for (i =0 ; i < p->nchunks; ++i) { +struct amdgpu_cs_chunk *chunk; + + chunk = &p->chunks[i]; + +switch (chunk->chunk_id) { +case AMDGPU_CHUNK_ID_DEPENDENCIES : +case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES : + r =amdgpu_cs_process_fence_dep (p, chunk); +if (r) +return r; +break ; +case AMDGPU_CHUNK_ID_SYNCOBJ_IN : + r =amdgpu_cs_process_syncobj_in_dep (p, chunk); +if (r) +return r; +break ; +case AMDGPU_CHUNK_ID_SYNCOBJ_OUT : + r =amdgpu_cs_process_syncobj_out_dep (p, chunk); +if (r) +return r; +break ; +case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT : + r =amdgpu_cs_process_syncobj_timeline_in_dep (p, chunk); +if (r) +return r; +break ; +case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL : + r =amdgpu_cs_process_syncobj_timeline_out_dep (p, chunk); +if (r) +return r; +break ; + } + } + +return 0 ; +} +/* Convert microseconds to bytes. */ static u64 us_to_bytes (struct amdgpu_device *adev,s64 us) {
@@ -659,25 +976,15 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,return r; } -static int amdgpu_cs_sync_rings (struct amdgpu_cs_parser *p) +static void trace_amdgpu_cs_ibs (struct amdgpu_cs_parser *parser) { -struct amdgpu_fpriv *fpriv = p->filp->driver_priv; -struct amdgpu_bo_list_entry *e; -int r; +int i; -list_for_each_entry (e, &p->validated, tv.head) { -struct amdgpu_bo *bo =ttm_to_amdgpu_bo (e->tv.bo); -struct dma_resv *resv = bo->tbo.base.resv; -enum amdgpu_sync_mode sync_mode; +if (!trace_amdgpu_cs_enabled ()) +return ; - sync_mode =amdgpu_bo_explicit_sync (bo) ? -AMDGPU_SYNC_EXPLICIT :AMDGPU_SYNC_NE_OWNER ; - r =amdgpu_sync_resv (p->adev, &p->job->sync, resv, sync_mode, - &fpriv->vm); -if (r) -return r; - } -return 0 ; +for (i =0 ; i < parser->job->num_ibs; i++) +trace_amdgpu_cs (parser, i); }static int amdgpu_cs_vm_handling (struct amdgpu_cs_parser *p)
@@ -733,417 +1040,119 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser *p) offset = m->start *AMDGPU_GPU_PAGE_SIZE ; kptr += va_start - offset; -if (ring->funcs->parse_cs) { -memcpy (ib->ptr, kptr, chunk_ib->ib_bytes); -amdgpu_bo_kunmap (aobj); - - r =amdgpu_ring_parse_cs (ring, p, p->job, ib); -if (r) -return r; - }else { - ib->ptr = (uint32_t *)kptr; - r =amdgpu_ring_patch_cs_in_place (ring, p, p->job, ib); -amdgpu_bo_kunmap (aobj); -if (r) -return r; - } - - j++; - } - } - -if (!p->job->vm) -return amdgpu_cs_sync_rings (p); - - - r =amdgpu_vm_clear_freed (adev, vm,NULL ); -if (r) -return r; - - r =amdgpu_vm_bo_update (adev, fpriv->prt_va, false); -if (r) -return r; - - r =amdgpu_sync_fence (&p->job->sync, fpriv->prt_va->last_pt_update); -if (r) -return r; - -if (fpriv->csa_va) { - bo_va = fpriv->csa_va; -BUG_ON (!bo_va); - r =amdgpu_vm_bo_update (adev, bo_va, false); -if (r) -return r; - - r =amdgpu_sync_fence (&p->job->sync, bo_va->last_pt_update); -if (r) -return r; - } - -amdgpu_bo_list_for_each_entry (e, p->bo_list) { -/* ignore duplicates */ - bo =ttm_to_amdgpu_bo (e->tv.bo); -if (!bo) -continue ; - - bo_va = e->bo_va; -if (bo_va ==NULL ) -continue ; - - r =amdgpu_vm_bo_update (adev, bo_va, false); -if (r) -return r; - - r =amdgpu_sync_fence (&p->job->sync, bo_va->last_pt_update); -if (r) -return r; - } - - r =amdgpu_vm_handle_moved (adev, vm); -if (r) -return r; - - r =amdgpu_vm_update_pdes (adev, vm, false); -if (r) -return r; - - r =amdgpu_sync_fence (&p->job->sync, vm->last_update); -if (r) -return r; - - p->job->vm_pd_addr =amdgpu_gmc_pd_addr (vm->root.bo); - -if (amdgpu_vm_debug) { -/* Invalidate all BOs to test for userspace bugs */ -amdgpu_bo_list_for_each_entry (e, p->bo_list) { -struct amdgpu_bo *bo =ttm_to_amdgpu_bo (e->tv.bo); - -/* ignore duplicates */ -if (!bo) -continue ; - -amdgpu_vm_bo_invalidate (adev, bo, false); - } - } - -return amdgpu_cs_sync_rings (p); -} - -static int amdgpu_cs_ib_fill (struct amdgpu_device *adev, -struct amdgpu_cs_parser *parser) -{ -struct amdgpu_fpriv *fpriv = parser->filp->driver_priv; -struct amdgpu_vm *vm = &fpriv->vm; -int r, ce_preempt =0 , de_preempt =0 ; -struct amdgpu_ring *ring; -int i, j; - -for (i =0 , j =0 ; i < parser->nchunks && j < parser->job->num_ibs; i++) { -struct amdgpu_cs_chunk *chunk; -struct amdgpu_ib *ib; -struct drm_amdgpu_cs_chunk_ib *chunk_ib; -struct drm_sched_entity *entity; - - chunk = &parser->chunks[i]; - ib = &parser->job->ibs[j]; - chunk_ib = (struct drm_amdgpu_cs_chunk_ib *)chunk->kdata; - -if (chunk->chunk_id !=AMDGPU_CHUNK_ID_IB ) -continue ; - -if (chunk_ib->ip_type ==AMDGPU_HW_IP_GFX && - chunk_ib->flags &AMDGPU_IB_FLAG_PREEMPT ) { -if (chunk_ib->flags &AMDGPU_IB_FLAG_CE ) - ce_preempt++; -else - de_preempt++; - -/* each GFX command submit allows 0 or 1 IB preemptible for CE & DE */ -if (ce_preempt >1 || de_preempt >1 ) -return -EINVAL ; - } - - r =amdgpu_ctx_get_entity (parser->ctx, chunk_ib->ip_type, - chunk_ib->ip_instance, chunk_ib->ring, - &entity); -if (r) -return r; - -if (chunk_ib->flags &AMDGPU_IB_FLAG_PREAMBLE ) - parser->job->preamble_status |= -AMDGPU_PREAMBLE_IB_PRESENT ; - -if (parser->entity && parser->entity != entity) -return -EINVAL ; - -/* Return if there is no run queue associated with this entity. -* Possibly because of disabled HW IP*/ -if (entity->rq ==NULL ) -return -EINVAL ; - - parser->entity = entity; - - ring =to_amdgpu_ring (entity->rq->sched); - r =amdgpu_ib_get (adev, vm, ring->funcs->parse_cs ? - chunk_ib->ib_bytes :0 , -AMDGPU_IB_POOL_DELAYED , ib); -if (r) { -DRM_ERROR ("Failed to get ib !\n" ); -return r; - } - - ib->gpu_addr = chunk_ib->va_start; - ib->length_dw = chunk_ib->ib_bytes /4 ; - ib->flags = chunk_ib->flags; - - j++; - } - -/* MM engine doesn't support user fences */ - ring =to_amdgpu_ring (parser->entity->rq->sched); -if (parser->job->uf_addr && ring->funcs->no_user_fence) -return -EINVAL ; - -return 0 ; -} - -static int amdgpu_cs_process_fence_dep (struct amdgpu_cs_parser *p, -struct amdgpu_cs_chunk *chunk) -{ -struct amdgpu_fpriv *fpriv = p->filp->driver_priv; -unsigned num_deps; -int i, r; -struct drm_amdgpu_cs_chunk_dep *deps; - - deps = (struct drm_amdgpu_cs_chunk_dep *)chunk->kdata; - num_deps = chunk->length_dw *4 / -sizeof (struct drm_amdgpu_cs_chunk_dep ); - -for (i =0 ; i < num_deps; ++i) { -struct amdgpu_ctx *ctx; -struct drm_sched_entity *entity; -struct dma_fence *fence; - - ctx =amdgpu_ctx_get (fpriv, deps[i].ctx_id); -if (ctx ==NULL ) -return -EINVAL ; - - r =amdgpu_ctx_get_entity (ctx, deps[i].ip_type, - deps[i].ip_instance, - deps[i].ring, &entity); -if (r) { -amdgpu_ctx_put (ctx); -return r; - } - - fence =amdgpu_ctx_get_fence (ctx, entity, deps[i].handle); -amdgpu_ctx_put (ctx); - -if (IS_ERR (fence)) -return PTR_ERR (fence); -else if (!fence) -continue ; +if (ring->funcs->parse_cs) { +memcpy (ib->ptr, kptr, chunk_ib->ib_bytes); +amdgpu_bo_kunmap (aobj); -if (chunk->chunk_id ==AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES ) { -struct drm_sched_fence *s_fence; -struct dma_fence *old = fence; + r =amdgpu_ring_parse_cs (ring, p, p->job, ib); +if (r) +return r; + }else { + ib->ptr = (uint32_t *)kptr; + r =amdgpu_ring_patch_cs_in_place (ring, p, p->job, ib); +amdgpu_bo_kunmap (aobj); +if (r) +return r; + } - s_fence =to_drm_sched_fence (fence); - fence =dma_fence_get (&s_fence->scheduled); -dma_fence_put (old); + j++; } - - r =amdgpu_sync_fence (&p->job->sync, fence); -dma_fence_put (fence); -if (r) -return r; } -return 0 ; -} -static int amdgpu_syncobj_lookup_and_add_to_sync (struct amdgpu_cs_parser *p, -uint32_t handle,u64 point, -u64 flags) -{ -struct dma_fence *fence; -int r; +if (!p->job->vm) +return 0 ; - r =drm_syncobj_find_fence (p->filp, handle, point, flags, &fence); -if (r) { -DRM_ERROR ("syncobj %u failed to find fence @ %llu (%d)!\n" , - handle, point, r); + r =amdgpu_vm_clear_freed (adev, vm,NULL ); +if (r)return r; - } - - r =amdgpu_sync_fence (&p->job->sync, fence); -dma_fence_put (fence); -return r; -} + r =amdgpu_vm_bo_update (adev, fpriv->prt_va, false); +if (r) +return r; -static int amdgpu_cs_process_syncobj_in_dep (struct amdgpu_cs_parser *p, -struct amdgpu_cs_chunk *chunk) -{ -struct drm_amdgpu_cs_chunk_sem *deps; -unsigned num_deps; -int i, r; + r =amdgpu_sync_fence (&p->job->sync, fpriv->prt_va->last_pt_update); +if (r) +return r; - deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata; - num_deps = chunk->length_dw *4 / -sizeof (struct drm_amdgpu_cs_chunk_sem ); -for (i =0 ; i < num_deps; ++i) { - r =amdgpu_syncobj_lookup_and_add_to_sync (p, deps[i].handle, -0 ,0 ); +if (fpriv->csa_va) { + bo_va = fpriv->csa_va; +BUG_ON (!bo_va); + r =amdgpu_vm_bo_update (adev, bo_va, false);if (r)return r; - } - -return 0 ; -} - - -static int amdgpu_cs_process_syncobj_timeline_in_dep (struct amdgpu_cs_parser *p, -struct amdgpu_cs_chunk *chunk) -{ -struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps; -unsigned num_deps; -int i, r; - syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata; - num_deps = chunk->length_dw *4 / -sizeof (struct drm_amdgpu_cs_chunk_syncobj ); -for (i =0 ; i < num_deps; ++i) { - r =amdgpu_syncobj_lookup_and_add_to_sync (p, - syncobj_deps[i].handle, - syncobj_deps[i].point, - syncobj_deps[i].flags); + r =amdgpu_sync_fence (&p->job->sync, bo_va->last_pt_update);if (r)return r; } -return 0 ; -} - -static int amdgpu_cs_process_syncobj_out_dep (struct amdgpu_cs_parser *p, -struct amdgpu_cs_chunk *chunk) -{ -struct drm_amdgpu_cs_chunk_sem *deps; -unsigned num_deps; -int i; - - deps = (struct drm_amdgpu_cs_chunk_sem *)chunk->kdata; - num_deps = chunk->length_dw *4 / -sizeof (struct drm_amdgpu_cs_chunk_sem ); - -if (p->post_deps) -return -EINVAL ; - - p->post_deps =kmalloc_array (num_deps,sizeof (*p->post_deps), -GFP_KERNEL ); - p->num_post_deps =0 ; +amdgpu_bo_list_for_each_entry (e, p->bo_list) { +/* ignore duplicates */ + bo =ttm_to_amdgpu_bo (e->tv.bo); +if (!bo) +continue ; -if (!p->post_deps) -return -ENOMEM ; + bo_va = e->bo_va; +if (bo_va ==NULL ) +continue ; + r =amdgpu_vm_bo_update (adev, bo_va, false); +if (r) +return r; -for (i =0 ; i < num_deps; ++i) { - p->post_deps[i].syncobj = -drm_syncobj_find (p->filp, deps[i].handle); -if (!p->post_deps[i].syncobj) -return -EINVAL ; - p->post_deps[i].chain =NULL ; - p->post_deps[i].point =0 ; - p->num_post_deps++; + r =amdgpu_sync_fence (&p->job->sync, bo_va->last_pt_update); +if (r) +return r; } -return 0 ; -} - - -static int amdgpu_cs_process_syncobj_timeline_out_dep (struct amdgpu_cs_parser *p, -struct amdgpu_cs_chunk *chunk) -{ -struct drm_amdgpu_cs_chunk_syncobj *syncobj_deps; -unsigned num_deps; -int i; - - syncobj_deps = (struct drm_amdgpu_cs_chunk_syncobj *)chunk->kdata; - num_deps = chunk->length_dw *4 / -sizeof (struct drm_amdgpu_cs_chunk_syncobj ); + r =amdgpu_vm_handle_moved (adev, vm); +if (r) +return r; -if (p->post_deps) -return -EINVAL ; + r =amdgpu_vm_update_pdes (adev, vm, false); +if (r) +return r; - p->post_deps =kmalloc_array (num_deps,sizeof (*p->post_deps), -GFP_KERNEL ); - p->num_post_deps =0 ; + r =amdgpu_sync_fence (&p->job->sync, vm->last_update); +if (r) +return r; -if (!p->post_deps) -return -ENOMEM ; + p->job->vm_pd_addr =amdgpu_gmc_pd_addr (vm->root.bo); -for (i =0 ; i < num_deps; ++i) { -struct amdgpu_cs_post_dep *dep = &p->post_deps[i]; +if (amdgpu_vm_debug) { +/* Invalidate all BOs to test for userspace bugs */ +amdgpu_bo_list_for_each_entry (e, p->bo_list) { +struct amdgpu_bo *bo =ttm_to_amdgpu_bo (e->tv.bo); - dep->chain =NULL ; -if (syncobj_deps[i].point) { - dep->chain =dma_fence_chain_alloc (); -if (!dep->chain) -return -ENOMEM ; - } +/* ignore duplicates */ +if (!bo) +continue ; - dep->syncobj =drm_syncobj_find (p->filp, - syncobj_deps[i].handle); -if (!dep->syncobj) { -dma_fence_chain_free (dep->chain); -return -EINVAL ; +amdgpu_vm_bo_invalidate (adev, bo, false); } - dep->point = syncobj_deps[i].point; - p->num_post_deps++; }return 0 ; } -static int amdgpu_cs_dependencies (struct amdgpu_device *adev, -struct amdgpu_cs_parser *p) +static int amdgpu_cs_sync_rings (struct amdgpu_cs_parser *p) { -int i, r; - -for (i =0 ; i < p->nchunks; ++i) { -struct amdgpu_cs_chunk *chunk; +struct amdgpu_fpriv *fpriv = p->filp->driver_priv; +struct amdgpu_bo_list_entry *e; +int r; - chunk = &p->chunks[i]; +list_for_each_entry (e, &p->validated, tv.head) { +struct amdgpu_bo *bo =ttm_to_amdgpu_bo (e->tv.bo); +struct dma_resv *resv = bo->tbo.base.resv; +enum amdgpu_sync_mode sync_mode; -switch (chunk->chunk_id) { -case AMDGPU_CHUNK_ID_DEPENDENCIES : -case AMDGPU_CHUNK_ID_SCHEDULED_DEPENDENCIES : - r =amdgpu_cs_process_fence_dep (p, chunk); -if (r) -return r; -break ; -case AMDGPU_CHUNK_ID_SYNCOBJ_IN : - r =amdgpu_cs_process_syncobj_in_dep (p, chunk); -if (r) -return r; -break ; -case AMDGPU_CHUNK_ID_SYNCOBJ_OUT : - r =amdgpu_cs_process_syncobj_out_dep (p, chunk); -if (r) -return r; -break ; -case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_WAIT : - r =amdgpu_cs_process_syncobj_timeline_in_dep (p, chunk); -if (r) -return r; -break ; -case AMDGPU_CHUNK_ID_SYNCOBJ_TIMELINE_SIGNAL : - r =amdgpu_cs_process_syncobj_timeline_out_dep (p, chunk); -if (r) -return r; -break ; - } + sync_mode =amdgpu_bo_explicit_sync (bo) ? +AMDGPU_SYNC_EXPLICIT :AMDGPU_SYNC_NE_OWNER ; + r =amdgpu_sync_resv (p->adev, &p->job->sync, resv, sync_mode, + &fpriv->vm); +if (r) +return r; } -return 0 ; }
@@ -1243,17 +1252,6 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,return r; } -static void trace_amdgpu_cs_ibs (struct amdgpu_cs_parser *parser) -{ -int i; - -if (!trace_amdgpu_cs_enabled ()) -return ; - -for (i =0 ; i < parser->job->num_ibs; i++) -trace_amdgpu_cs (parser, i); -} -/* Cleanup the parser structure */ static void amdgpu_cs_parser_fini (struct amdgpu_cs_parser *parser,int error,bool backoff)
@@ -1342,6 +1340,10 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)if (r) goto out; + r =amdgpu_cs_sync_rings (&parser); +if (r) + goto out; + r =amdgpu_cs_submit (&parser, data); out:amdgpu_cs_parser_fini (&parser, r, reserved_buffers);
Signature · 1 line
2.25.1
Alex Deucher
Reviewed-byQuoted 9 lines · Christian König
Hey Alex,
I've decided to split this patch set into two because we still can't figure out where the VCN regressions come from.
Ruijing tested them and confirmed that they don't regress VCN.
Can you and maybe Felix take a look and review them?
Looks good to me. Series is:
Quoted 5 lines
Thanks,
Christian.