drm/amd/amdgpu embed hw_fence into amdgpu_job
Subsystems (5)
PATCH v2 1/2 drm/amd/amdgpu embed hw_fence into amdgpu_job
From: Jack Zhang <[email protected]>
Why: Previously hw fence is alloced separately with job. It caused historical lifetime issues and corner cases. The ideal situation is to take fence to manage both job and fence's lifetime, and simplify the design of gpu-scheduler.
How:
We propose to embed hw_fence into amdgpu_job.
1. We cover the normal job submission by this method.
2. For ib_test, and submit without a parent job keep the legacy way to create a hw fence separately.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 1 - drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 62 ++++++++++++++++----- drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 35 ++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_job.h | 4 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +- 8 files changed, 80 insertions(+), 30 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -1
@@ -714,7 +714,6 @@ int amdgpu_amdkfd_submit_ib(struct kgd_dev *kgd, enum kgd_engine_type engine, ret =dma_fence_wait (f, false); err_ib_sched: -dma_fence_put (f);amdgpu_job_free (job); err:return ret;
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +1 -1
@@ -1414,7 +1414,7 @@ static void amdgpu_ib_preempt_mark_partial_job(struct amdgpu_ring *ring)continue ; } job =to_amdgpu_job (s_job); -if (preempted && job->fence == fence) +if (preempted && (&job->hw_fence) == fence)/* mark the job as preempted */ job->preemption_status |=AMDGPU_IB_PREEMPTED ; }
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +49 -13
105 lines not on this page · raw message
drivers/gpu/drm/amd/amdgpu/amdgpu_ib.c +1 -1
@@ -262,7 +262,7 @@ int amdgpu_ib_schedule(struct amdgpu_ring *ring, unsigned num_ibs, fence_flags | AMDGPU_FENCE_FLAG_64BIT); } - r =amdgpu_fence_emit (ring, f, fence_flags); + r =amdgpu_fence_emit (ring, f, job, fence_flags);if (r) {dev_err (adev->dev,"failed to emit fence (%d)\n" , r);if (job && job->vmid)
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +24 -11
@@ -114,11 +114,16 @@ void amdgpu_job_free_resources(struct amdgpu_job *job) {struct amdgpu_ring *ring =to_amdgpu_ring (job->base.sched);struct dma_fence *f; +struct dma_fence *hw_fence;unsigned i; -/* use sched fence if available */ - f = job->base.s_fence ? &job->base.s_fence->finished : job->fence; +if (job->hw_fence.ops ==NULL ) + hw_fence = job->external_hw_fence; +else + hw_fence = &job->hw_fence; +/* use sched fence if available */ + f = job->base.s_fence ? &job->base.s_fence->finished : hw_fence;for (i =0 ; i < job->num_ibs; ++i)amdgpu_ib_free (ring->adev, &job->ibs[i], f); }
@@ -129,20 +134,27 @@ static void amdgpu_job_free_cb(struct drm_sched_job *s_job)drm_sched_job_cleanup (s_job); -dma_fence_put (job->fence);amdgpu_sync_free (&job->sync);amdgpu_sync_free (&job->sched_sync); -kfree (job); + +/* only put the hw fence if has embedded fence */ +if (job->hw_fence.ops !=NULL ) +dma_fence_put (&job->hw_fence); +else +kfree (job); }void amdgpu_job_free (struct amdgpu_job *job) {amdgpu_job_free_resources (job); - -dma_fence_put (job->fence);amdgpu_sync_free (&job->sync);amdgpu_sync_free (&job->sched_sync); -kfree (job); + +/* only put the hw fence if has embedded fence */ +if (job->hw_fence.ops !=NULL ) +dma_fence_put (&job->hw_fence); +else +kfree (job); } int amdgpu_job_submit(struct amdgpu_job *job, struct drm_sched_entity *entity,
@@ -171,11 +183,14 @@ int amdgpu_job_submit_direct(struct amdgpu_job *job, struct amdgpu_ring *ring, job->base.sched = &ring->sched; r =amdgpu_ib_schedule (ring, job->num_ibs, job->ibs,NULL , fence); - job->fence =dma_fence_get (*fence); +/* record external_hw_fence for direct submit */ + job->external_hw_fence =dma_fence_get (*fence);if (r)return r;amdgpu_job_free (job); +dma_fence_put (*fence); +return 0 ; }
@@ -233,10 +248,8 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)if (r)DRM_ERROR ("Error scheduling IBs (%d)\n" , r); } -/* if gpu reset, hw fence will be replaced here */ -dma_fence_put (job->fence); - job->fence =dma_fence_get (fence); +dma_fence_get (fence);amdgpu_job_free_resources (job); fence = r ?ERR_PTR (r) : fence;
drivers/gpu/drm/amd/amdgpu/amdgpu_job.h +3 -1
@@ -46,7 +46,9 @@ struct amdgpu_job {struct amdgpu_sync sync;struct amdgpu_sync sched_sync;struct amdgpu_ib *ibs; -struct dma_fence *fence;/* the hw fence */ +struct dma_fence hw_fence; +struct amdgpu_ring *ring; +struct dma_fence *external_hw_fence;uint32_t preamble_status;uint32_t preemption_status;uint32_t num_ibs;
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -1
@@ -118,7 +118,7 @@ int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring, unsigned irq_type);void amdgpu_fence_driver_suspend (struct amdgpu_device *adev);void amdgpu_fence_driver_resume (struct amdgpu_device *adev); -int amdgpu_fence_emit (struct amdgpu_ring *ring,struct dma_fence **fence, +int amdgpu_fence_emit (struct amdgpu_ring *ring,struct dma_fence **fence,struct amdgpu_job *job,unsigned flags);int amdgpu_fence_emit_polling (struct amdgpu_ring *ring,uint32_t *s,uint32_t timeout);
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +1 -1
@@ -1216,7 +1216,7 @@ int amdgpu_vm_flush(struct amdgpu_ring *ring, struct amdgpu_job *job,amdgpu_gmc_emit_pasid_mapping (ring, job->vmid, job->pasid);if (vm_flush_needed || pasid_mapping_needed) { - r =amdgpu_fence_emit (ring, &fence,0 ); + r =amdgpu_fence_emit (ring, &fence,NULL ,0 );if (r)return r; }
Signature · 6 lines
2.25.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
PATCH v2 1/1 drm: add tdr support for embeded hw_fence
[Why]
After embeded hw_fence to amdgpu_job, we need to add tdr support for this feature.
[How]
1. Add a resubmit_flag for resubmit jobs.
2. Clear job fence from RCU and force complete vm flush fences in pre_asic_reset
3. skip dma_fence_get for resubmit jobs and add a dma_fence_put for guilty jobs.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 12 +++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 13 +++++++++---- drivers/gpu/drm/amd/amdgpu/amdgpu_job.c | 4 +++- drivers/gpu/drm/scheduler/sched_main.c | 1 + include/drm/gpu_scheduler.h | 1 + 5 files changed, 25 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11 -1
@@ -4382,7 +4382,7 @@ int amdgpu_device_mode1_reset(struct amdgpu_device *adev)int amdgpu_device_pre_asic_reset (struct amdgpu_device *adev,struct amdgpu_reset_context *reset_context) { -int i, r =0 ; +int i, j, r =0 ;struct amdgpu_job *job =NULL ;bool need_full_reset =test_bit (AMDGPU_NEED_FULL_RESET , &reset_context->flags);
@@ -4406,6 +4406,16 @@ int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,if (!ring || !ring->sched.thread)continue ; +/*clear job fence from fence drv to avoid force_completion +*leave NULL and vm flush fence in fence drv */ +for (j =0 ; j <= ring->fence_drv.num_fences_mask; j ++) { +struct dma_fence *old,**ptr; + ptr = &ring->fence_drv.fences[j]; + old =rcu_dereference_protected (*ptr,1 ); + if (old && test_bit(DMA_FENCE_FLAG_USER_BITS, &old->flags))) { +RCU_INIT_POINTER (*ptr,NULL ); + } + }/* after all hw jobs are reset, hw fence is meaningless, so force_completion */ amdgpu_fence_driver_force_completion (ring); }
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +9 -4
@@ -157,10 +157,15 @@ int amdgpu_fence_emit(struct amdgpu_ring *ring, struct dma_fence **f, struct amd } seq = ++ring->fence_drv.sync_seq; -dma_fence_init (fence, &amdgpu_fence_ops, - &ring->fence_drv.lock, - adev->fence_context + ring->idx, - seq); +if (job !=NULL && job->base.resubmit_flag ==1 ) { +/* reset seq for resubmitted jobs */ + fence->seqno = seq; + }else { +dma_fence_init (fence, &amdgpu_fence_ops, + &ring->fence_drv.lock, + adev->fence_context + ring->idx, + seq); + }if (job !=NULL ) {/* mark this fence has a parent job */
drivers/gpu/drm/amd/amdgpu/amdgpu_job.c +3 -1
@@ -241,6 +241,7 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)dma_fence_set_error (finished, -ECANCELED );/* skip IB as well if VRAM lost */ if (finished->error <0 ) { +dma_fence_put (&job->hw_fence);DRM_INFO ("Skip scheduling IBs!\n" ); }else { r = amdgpu_ib_schedule(ring, job->num_ibs, job->ibs, job,
@@ -249,7 +250,8 @@ static struct dma_fence *amdgpu_job_run(struct drm_sched_job *sched_job)DRM_ERROR ("Error scheduling IBs (%d)\n" , r); } -dma_fence_get (fence); +if (!job->base.resubmit_flag) +dma_fence_get (fence);amdgpu_job_free_resources (job); fence = r ?ERR_PTR (r) : fence;
drivers/gpu/drm/scheduler/sched_main.c +1 -0
@@ -544,6 +544,7 @@ void drm_sched_resubmit_jobs_ext(struct drm_gpu_scheduler *sched, int max)dma_fence_set_error (&s_fence->finished, -ECANCELED );dma_fence_put (s_job->s_fence->parent); + s_job->resubmit_flag =1 ; fence = sched->ops->run_job (s_job); i++;
include/drm/gpu_scheduler.h +1 -0
@@ -198,6 +198,7 @@ struct drm_sched_job {enum drm_sched_priority s_priority;struct drm_sched_entity *entity;struct dma_fence_cb cb; +int resubmit_flag; }; static inline bool drm_sched_invalidate_job(struct drm_sched_job *s_job,
Signature · 6 lines
2.25.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx