drm/amdgpu: handle pipeline sync without a VM fence
Subsystems (2)
Alex Deucher
maintainerPATCH 1/1 drm/amdgpu: handle pipeline sync without a VM fence
If we end up emitting a VM fence keep pipeline sync associated with that fence. If not, emit them as part of the IB fence.
v2: fix need_pipe_sync handling
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +5 -1
@@ -222,7 +222,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, vm_af = job->hw_vm_fence;/* VM sequence */ vm_af->ib_wptr = ring->wptr; -amdgpu_vm_flush (ring, job, need_pipe_sync, &emit_spm_needed, +amdgpu_vm_flush (ring, job, &need_pipe_sync, &emit_spm_needed, &emit_gds_needed); vm_af->ib_dw_size =amdgpu_ring_get_dw_distance (ring, vm_af->ib_wptr, ring->wptr);
@@ -235,6 +235,10 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,if (ring->funcs->insert_start) ring->funcs->insert_start (ring); +/* this may have been handled by amdgpu_vm_flush */ +if (need_pipe_sync) +amdgpu_ring_emit_pipeline_sync (ring); +if (emit_spm_needed) adev->gfx.rlc.funcs->update_spm_vmid (adev, ring->xcc_id, ring, job->vmid);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5 -3
@@ -772,7 +772,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,* Emit a VM flush when it is necessary. */ void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool need_pipe_sync,bool *emit_spm_needed, +bool *need_pipe_sync,bool *emit_spm_needed,bool *emit_gds_needed) {struct amdgpu_device *adev = ring->adev;
@@ -827,7 +827,7 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (gds_switch_needed && emit_fence) *emit_gds_needed = false; -if (!vm_flush_needed && !gds_switch_needed && !need_pipe_sync && +if (!vm_flush_needed && !gds_switch_needed && !(*need_pipe_sync) && !cleaner_shader_needed && !spm_update_needed)return ;
@@ -847,8 +847,10 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, patch =amdgpu_ring_init_cond_exec (ring, ring->cond_exe_gpu_addr); -if (need_pipe_sync) +if (emit_fence && *need_pipe_sync) {amdgpu_ring_emit_pipeline_sync (ring); + *need_pipe_sync = false; + }if (cleaner_shader_needed) ring->funcs->emit_cleaner_shader (ring);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1 -1
@@ -512,7 +512,7 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,int (*callback)(void *p,struct amdgpu_bo *bo), void *param);void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool need_pipe_sync,bool *emit_spm_needed, +bool *need_pipe_sync,bool *emit_spm_needed,bool *emit_gds_needed);int amdgpu_vm_update_pdes (struct amdgpu_device *adev,struct amdgpu_vm *vm,bool immediate);
Signature · 1 line
2.55.0
Ping?
Quoted 90 lines · Alex Deucher
If we end up emitting a VM fence keep pipeline sync associated with that fence. If not, emit them as part of the IB fence.
v2: fix
need_pipe_synchandlingCc David Rosca <[email protected]>Fixes cb1e657ccac8 ("drm/amdgpu: handle GDS and SPM without a VM fence")Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +5
-1@@ -222,7 +222,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, vm_af = job->hw_vm_fence;/* VM sequence */ vm_af->ib_wptr = ring->wptr; -amdgpu_vm_flush (ring, job, need_pipe_sync, &emit_spm_needed, +amdgpu_vm_flush (ring, job, &need_pipe_sync, &emit_spm_needed, &emit_gds_needed); vm_af->ib_dw_size =amdgpu_ring_get_dw_distance (ring, vm_af->ib_wptr, ring->wptr);@@ -235,6 +235,10 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,if (ring->funcs->insert_start) ring->funcs->insert_start (ring); +/* this may have been handled by amdgpu_vm_flush */ +if (need_pipe_sync) +amdgpu_ring_emit_pipeline_sync (ring); +if (emit_spm_needed) adev->gfx.rlc.funcs->update_spm_vmid (adev, ring->xcc_id, ring, job->vmid);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +5
-3@@ -772,7 +772,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,* Emit a VM flush when it is necessary. */ void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool need_pipe_sync,bool *emit_spm_needed, +bool *need_pipe_sync,bool *emit_spm_needed,bool *emit_gds_needed) {struct amdgpu_device *adev = ring->adev;@@ -827,7 +827,7 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (gds_switch_needed && emit_fence) *emit_gds_needed = false; -if (!vm_flush_needed && !gds_switch_needed && !need_pipe_sync && +if (!vm_flush_needed && !gds_switch_needed && !(*need_pipe_sync) && !cleaner_shader_needed && !spm_update_needed)return ;@@ -847,8 +847,10 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, patch =amdgpu_ring_init_cond_exec (ring, ring->cond_exe_gpu_addr); -if (need_pipe_sync) +if (emit_fence && *need_pipe_sync) {amdgpu_ring_emit_pipeline_sync (ring); + *need_pipe_sync = false; + }if (cleaner_shader_needed) ring->funcs->emit_cleaner_shader (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-2@@ -512,7 +512,7 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,int (*callback)(void *p,struct amdgpu_bo *bo), void *param);void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool need_pipe_sync,bool *emit_spm_needed, +bool *need_pipe_sync,bool *emit_spm_needed,bool *emit_gds_needed);int amdgpu_vm_update_pdes (struct amdgpu_device *adev,struct amdgpu_vm *vm,bool immediate); --2.55.0
Quoted 53 lines · Alex Deucher
If we end up emitting a VM fence keep pipeline sync associated with that fence. If not, emit them as part of the IB fence.
v2: fix
need_pipe_synchandlingCc David Rosca <[email protected]>Fixes cb1e657ccac8 ("drm/amdgpu: handle GDS and SPM without a VM fence")Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +5
-1@@ -222,7 +222,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, vm_af = job->hw_vm_fence;/* VM sequence */ vm_af->ib_wptr = ring->wptr; -amdgpu_vm_flush (ring, job, need_pipe_sync, &emit_spm_needed, +amdgpu_vm_flush (ring, job, &need_pipe_sync, &emit_spm_needed, &emit_gds_needed); vm_af->ib_dw_size =amdgpu_ring_get_dw_distance (ring, vm_af->ib_wptr, ring->wptr);@@ -235,6 +235,10 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,if (ring->funcs->insert_start) ring->funcs->insert_start (ring); +/* this may have been handled by amdgpu_vm_flush */ +if (need_pipe_sync) +amdgpu_ring_emit_pipeline_sync (ring); +if (emit_spm_needed) adev->gfx.rlc.funcs->update_spm_vmid (adev, ring->xcc_id, ring, job->vmid);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -772,7 +772,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,* Emit a VM flush when it is necessary. */ void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool need_pipe_sync,bool *emit_spm_needed, +bool *need_pipe_sync,bool *emit_spm_needed,bool *emit_gds_needed) {struct amdgpu_device *adev = ring->adev;
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, · line 830
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -827,7 +827,7 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (gds_switch_needed && emit_fence) *emit_gds_needed = false; - if (!vm_flush_needed && !gds_switch_needed && !need_pipe_sync && + if (!vm_flush_needed && !gds_switch_needed && !(*need_pipe_sync) &&
The only time need_pipe_sync in this check makes a difference is when only pasid_mapping_needed (which is missing from this condition, is that intended?) is true and the rest *_needed are false. Then emit_fence is true and pipeline_sync is emitted in this function which looks fine.
If pasid_mapping_needed and all other *_needed are false, then emit_fence is false and the rest of the function effectively does nothing. emit_pipeline_sync will be called from amdgpu_ib_schedule. While this works, I think it would be better to return early here?
David
Quoted 28 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-1!cleaner_shader_needed && !spm_update_needed)return ;@@ -847,8 +847,10 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, patch =amdgpu_ring_init_cond_exec (ring, ring->cond_exe_gpu_addr); -if (need_pipe_sync) +if (emit_fence && *need_pipe_sync) {amdgpu_ring_emit_pipeline_sync (ring); + *need_pipe_sync = false; + }if (cleaner_shader_needed) ring->funcs->emit_cleaner_shader (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-1@@ -512,7 +512,7 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,int (*callback)(void *p,struct amdgpu_bo *bo), void *param);void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool need_pipe_sync,bool *emit_spm_needed, +bool *need_pipe_sync,bool *emit_spm_needed,bool *emit_gds_needed);int amdgpu_vm_update_pdes (struct amdgpu_device *adev,struct amdgpu_vm *vm,bool immediate);
Quoted 67 lines · David Rosca
Quoted 53 lines · Alex Deucher
If we end up emitting a VM fence keep pipeline sync associated with that fence. If not, emit them as part of the IB fence.
v2: fix
need_pipe_synchandlingCc David Rosca <[email protected]>Fixes cb1e657ccac8 ("drm/amdgpu: handle GDS and SPM without a VM fence")Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 6 +++++- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 8 +++++--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +5
-1@@ -222,7 +222,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs, vm_af = job->hw_vm_fence;/* VM sequence */ vm_af->ib_wptr = ring->wptr; -amdgpu_vm_flush (ring, job, need_pipe_sync, &emit_spm_needed, +amdgpu_vm_flush (ring, job, &need_pipe_sync, &emit_spm_needed, &emit_gds_needed); vm_af->ib_dw_size =amdgpu_ring_get_dw_distance (ring, vm_af->ib_wptr, ring->wptr);@@ -235,6 +235,10 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned int num_ibs,if (ring->funcs->insert_start) ring->funcs->insert_start (ring); +/* this may have been handled by amdgpu_vm_flush */ +if (need_pipe_sync) +amdgpu_ring_emit_pipeline_sync (ring); +if (emit_spm_needed) adev->gfx.rlc.funcs->update_spm_vmid (adev, ring->xcc_id, ring, job->vmid);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -772,7 +772,7 @@ bool amdgpu_vm_need_pipeline_sync(struct amdgpu_ring *ring,* Emit a VM flush when it is necessary. */ void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool need_pipe_sync,bool *emit_spm_needed, +bool *need_pipe_sync,bool *emit_spm_needed,bool *emit_gds_needed) {struct amdgpu_device *adev = ring->adev;drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, · line 830
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1
-1@@ -827,7 +827,7 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,if (gds_switch_needed && emit_fence) *emit_gds_needed = false; - if (!vm_flush_needed && !gds_switch_needed && !need_pipe_sync && + if (!vm_flush_needed && !gds_switch_needed && !(*need_pipe_sync) &&The only time
need_pipe_syncin this check makes a difference is when onlypasid_mapping_needed(which is missing from this condition, is that intended?) is true and the rest*_neededare false. Thenemit_fenceis true andpipeline_syncis emitted in this function which looks fine.
Quoted 4 lines
If
pasid_mapping_neededand all other*_neededare false, thenemit_fenceis false and the rest of the function effectively does nothing.emit_pipeline_syncwill be called fromamdgpu_ib_schedule. While this works, I think it would be better to return early here?
I see what you are saying. I think this could be simplified to
if (!emit_fence)
return;
If we are not emitting the fence, everything needs to be handled in amdgpu_ib_schedule().
Alex
Quoted 31 lines
David
Quoted 28 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +3
-1!cleaner_shader_needed && !spm_update_needed)return ;@@ -847,8 +847,10 @@ void amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job, patch =amdgpu_ring_init_cond_exec (ring, ring->cond_exe_gpu_addr); -if (need_pipe_sync) +if (emit_fence && *need_pipe_sync) {amdgpu_ring_emit_pipeline_sync (ring); + *need_pipe_sync = false; + }if (cleaner_shader_needed) ring->funcs->emit_cleaner_shader (ring);drivers/gpu/drm/amd/amdgpu/amdgpu_vm.h +1
-1@@ -512,7 +512,7 @@ int amdgpu_vm_validate(struct amdgpu_device *adev, struct amdgpu_vm *vm,int (*callback)(void *p,struct amdgpu_bo *bo), void *param);void amdgpu_vm_flush (struct amdgpu_ring *ring,struct amdgpu_job *job, -bool need_pipe_sync,bool *emit_spm_needed, +bool *need_pipe_sync,bool *emit_spm_needed,bool *emit_gds_needed);int amdgpu_vm_update_pdes (struct amdgpu_device *adev,struct amdgpu_vm *vm,bool immediate);