drm/amd/amdgpu implement tdr advanced mode
Subsystems (4)
PATCH v6 1/1 drm/amd/amdgpu implement tdr advanced mode
[Why]
Previous tdr design treats the first job in job_timeout as the bad job. But sometimes a later bad compute job can block a good gfx job and cause an unexpected gfx job timeout because gfx and compute ring share internal GC HW mutually.
[How]
This patch implements an advanced tdr mode.It involves an additinal synchronous pre-resubmit step(Step0 Resubmit) before normal resubmit step in order to find the real bad job.
1. At Step0 Resubmit stage, it synchronously submits and pends for the first job being signaled. If it gets timeout, we identify it as guilty and do hw reset. After that, we would do the normal resubmit step to resubmit left jobs.
2. Re-insert Bailing job to mirror_list, and leave it to be handled by the main reset thread.
3. For whole gpu reset(vram lost), do resubmit as the old way.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 72 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 75 ++++++++++++++++++++++ include/drm/gpu_scheduler.h | 2 + 4 files changed, 148 insertions(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +70 -2
@@ -4639,6 +4639,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,int i, r =0 ;bool need_emergency_restart = false;bool audio_suspended = false; +int tmp_vram_lost_counter;/* * Special case: RAS triggered and full reset isn't supported
@@ -4689,9 +4690,14 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,dev_info (adev->dev,"Bailing on TDR for s_job:%llx, as another already in progress" , job ? job->base.id :-1 ); -/* even we skipped this reset, still need to set the job to guilty */ -if (job) +if (job) { +/* re-insert node to avoid memory leak */ +spin_lock (&job->base.sched->job_list_lock); +list_add (&job->base.node, &job->base.sched->pending_list); +spin_unlock (&job->base.sched->job_list_lock); +/* even we skipped this reset, still need to set the job to guilty */ drm_sched_increase_karma (&job->base); + } goto skip_recovery; }
@@ -4788,6 +4794,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, } } + tmp_vram_lost_counter =atomic_read (&((adev)->vram_lost_counter));/* Actual ASIC resets if needed.*/ /* TODO Implement XGMI hive reset logic for SRIOV */ if (amdgpu_sriov_vf (adev)) {
@@ -4805,6 +4812,67 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,/* Post ASIC reset for all devs .*/ list_for_each_entry (tmp_adev, device_list_handle, gmc.xgmi.head) { +if (amdgpu_gpu_recovery ==2 && + !(tmp_vram_lost_counter <atomic_read (&adev->vram_lost_counter))) { + +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; +int ret =0 ; +struct drm_sched_job *s_job; + +if (!ring || !ring->sched.thread) +continue ; + +/* No point to resubmit jobs if we didn't HW reset*/ +if (!tmp_adev->asic_reset_res && !job_signaled) { + + s_job = list_first_entry_or_null(&ring->sched.pending_list, struct drm_sched_job, list); +if (s_job ==NULL ) +continue ; + +/* clear job's guilty and depend the folowing step to decide the real one */ +drm_sched_reset_karma (s_job); +drm_sched_resubmit_jobs2 (&ring->sched,1 ); + ret =dma_fence_wait_timeout (s_job->s_fence->parent, false, ring->sched.timeout); + +if (ret ==0 ) {/* timeout */ +DRM_ERROR ("Found the real bad job! ring:%s, job_id:%llx\n" , ring->sched.name, s_job->id); +/* set guilty */ +drm_sched_increase_karma (s_job); + +/* do hw reset */ +if (amdgpu_sriov_vf (adev)) { +amdgpu_virt_fini_data_exchange (adev); + r =amdgpu_device_reset_sriov (adev, false); +if (r) + adev->asic_reset_res = r; + }else { + r =amdgpu_do_asic_reset (hive, device_list_handle, &need_full_reset, false); +if (r && r == -EAGAIN ) + goto retry; + } + +/* add reset counter so that the following resubmitted job could flush vmid */ +atomic_inc (&tmp_adev->gpu_reset_counter); +continue ; + } + +/* got the hw fence, signal finished fence */ +atomic_dec (&ring->sched.num_jobs); +dma_fence_get (&s_job->s_fence->finished); +dma_fence_signal (&s_job->s_fence->finished); +dma_fence_put (&s_job->s_fence->finished); + + +/* remove node from list and free the job */ +spin_lock (&ring->sched.job_list_lock); +list_del_init (&s_job->node); +spin_unlock (&ring->sched.job_list_lock); + ring->sched.ops->free_job (s_job); + } + } + } +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i];
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1 -1
@@ -509,7 +509,7 @@ module_param_named(compute_multipipe, amdgpu_compute_multipipe, int, 0444);* DOC: gpu_recovery (int) * Set to enable GPU recovery mechanism (1 = enable, 0 = disable). The default is -1 (auto, disabled except SRIOV). */ -MODULE_PARM_DESC (gpu_recovery,"Enable GPU recovery mechanism, (1 = enable, 0 = disable, -1 = auto)" ); +MODULE_PARM_DESC (gpu_recovery,"Enable GPU recovery mechanism, (2 = advanced tdr mode, 1 = enable, 0 = disable, -1 = auto)" );module_param_named (gpu_recovery, amdgpu_gpu_recovery, int,0444 );/**
drivers/gpu/drm/scheduler/sched_main.c +75 -0
81 lines not on this page · raw message
include/drm/gpu_scheduler.h +2 -0
@@ -321,7 +321,9 @@ void drm_sched_wakeup(struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched); +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int max);void drm_sched_increase_karma (struct drm_sched_job *bad); +void drm_sched_reset_karma (struct drm_sched_job *bad);bool drm_sched_dependency_optimized (struct dma_fence * fence,struct drm_sched_entity *entity);void drm_sched_fault (struct drm_gpu_scheduler *sched);
Signature · 6 lines
2.25.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 45 lines · Jack Zhang
[Why]
Previous tdr design treats the first job injob_timeoutas the bad job. But sometimes a later bad compute job can block a good gfx job and cause an unexpected gfx job timeout because gfx and compute ring share internal GC HW mutually.[How]
This patch implements an advanced tdr mode.It involves an additinal synchronous pre-resubmit step(Step0 Resubmit) before normal resubmit step in order to find the real bad job.1. At Step0 Resubmit stage, it synchronously submits and pends for the first job being signaled. If it gets timeout, we identify it as guilty and do hw reset. After that, we would do the normal resubmit step to resubmit left jobs.
2. Re-insert Bailing job to
mirror_list, and leave it to be handled by the main reset thread.3. For whole gpu reset(vram lost), do resubmit as the old way.
Signed-off-by Jack Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 72 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 75 ++++++++++++++++++++++ include/drm/gpu_scheduler.h | 2 + 4 files changed, 148 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0@@ -4639,6 +4639,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,int i, r =0 ;bool need_emergency_restart = false;bool audio_suspended = false; +int tmp_vram_lost_counter;/* * Special case: RAS triggered and full reset isn't supported @@ -4689,9 +4690,14 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,dev_info (adev->dev,"Bailing on TDR for s_job:%llx, as another already in progress" , job ? job->base.id :-1 );
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev, · line 4700
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-2-/* even we skipped this reset, still need to set the job to guilty */ -if (job) +if (job) { +/* re-insert node to avoid memory leak */ +spin_lock (&job->base.sched->job_list_lock); +list_add (&job->base.node, &job->base.sched->pending_list); +spin_unlock (&job->base.sched->job_list_lock); +/* even we skipped this reset, still need to set the job to guilty */ drm_sched_increase_karma (&job->base); + }
I think this piece should be in a standalone
patch as it comes to fix a bug of leaking
jobs and not directly related to find actual
guilty job. Also, this is not the only place
where the problem arises - it also arises
in other drivers where they check that guilty
job's fence already signaled and bail out before
reinsertion of bad job to mirror list. Seems to me
better fix would be to handle this within scheduler
code by adding specific return value to drm_sched_backend_ops.timedout_job marking that the code terminated early - before calling drm_sched_stop and so drm_sched_job_timedout would know this and then reinsert the job back to mirror_list itself.
Quoted 128 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +62
-0goto skip_recovery; }@@ -4788,6 +4794,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, } } + tmp_vram_lost_counter =atomic_read (&((adev)->vram_lost_counter));/* Actual ASIC resets if needed.*/ /* TODO Implement XGMI hive reset logic for SRIOV */ if (amdgpu_sriov_vf (adev)) {@@ -4805,6 +4812,67 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,/* Post ASIC reset for all devs .*/ list_for_each_entry (tmp_adev, device_list_handle, gmc.xgmi.head) { +if (amdgpu_gpu_recovery ==2 && + !(tmp_vram_lost_counter <atomic_read (&adev->vram_lost_counter))) { + +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; +int ret =0 ; +struct drm_sched_job *s_job; + +if (!ring || !ring->sched.thread) +continue ; + +/* No point to resubmit jobs if we didn't HW reset*/ +if (!tmp_adev->asic_reset_res && !job_signaled) { + + s_job = list_first_entry_or_null(&ring->sched.pending_list, struct drm_sched_job, list); +if (s_job ==NULL ) +continue ; + +/* clear job's guilty and depend the folowing step to decide the real one */ +drm_sched_reset_karma (s_job); +drm_sched_resubmit_jobs2 (&ring->sched,1 ); + ret =dma_fence_wait_timeout (s_job->s_fence->parent, false, ring->sched.timeout); + +if (ret ==0 ) {/* timeout */ +DRM_ERROR ("Found the real bad job! ring:%s, job_id:%llx\n" , ring->sched.name, s_job->id); +/* set guilty */ +drm_sched_increase_karma (s_job); + +/* do hw reset */ +if (amdgpu_sriov_vf (adev)) { +amdgpu_virt_fini_data_exchange (adev); + r =amdgpu_device_reset_sriov (adev, false); +if (r) + adev->asic_reset_res = r; + }else { + r =amdgpu_do_asic_reset (hive, device_list_handle, &need_full_reset, false); +if (r && r == -EAGAIN ) + goto retry; + } + +/* add reset counter so that the following resubmitted job could flush vmid */ +atomic_inc (&tmp_adev->gpu_reset_counter); +continue ; + } + +/* got the hw fence, signal finished fence */ +atomic_dec (&ring->sched.num_jobs); +dma_fence_get (&s_job->s_fence->finished); +dma_fence_signal (&s_job->s_fence->finished); +dma_fence_put (&s_job->s_fence->finished); + + +/* remove node from list and free the job */ +spin_lock (&ring->sched.job_list_lock); +list_del_init (&s_job->node); +spin_unlock (&ring->sched.job_list_lock); + ring->sched.ops->free_job (s_job); + } + } + } +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i];drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +1
-1@@ -509,7 +509,7 @@ module_param_named(compute_multipipe, amdgpu_compute_multipipe, int, 0444);* DOC: gpu_recovery (int) * Set to enable GPU recovery mechanism (1 = enable, 0 = disable). The default is -1 (auto, disabled except SRIOV). */ -MODULE_PARM_DESC (gpu_recovery,"Enable GPU recovery mechanism, (1 = enable, 0 = disable, -1 = auto)" ); +MODULE_PARM_DESC (gpu_recovery,"Enable GPU recovery mechanism, (2 = advanced tdr mode, 1 = enable, 0 = disable, -1 = auto)" );module_param_named (gpu_recovery, amdgpu_gpu_recovery, int,0444 );/** drivers/gpu/drm/scheduler/sched_main.c +28
-0@@ -395,6 +395,81 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) }EXPORT_SYMBOL (drm_sched_increase_karma); + +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int max) +{ +struct drm_sched_job *s_job, *tmp; +uint64_t guilty_context; +bool found_guilty = false; +struct dma_fence *fence; +int i =0 ; + +list_for_each_entry_safe (s_job, tmp, &sched->pending_list, list) { +struct drm_sched_fence *s_fence = s_job->s_fence; + +if (i >= max) +break ; + +if (!found_guilty &&atomic_read (&s_job->karma) > sched->hang_limit) { + found_guilty = true; + guilty_context = s_job->s_fence->scheduled.context; + } + +if (found_guilty && s_job->s_fence->scheduled.context == guilty_context) +dma_fence_set_error (&s_fence->finished, -ECANCELED ); + +dma_fence_put (s_job->s_fence->parent); + fence = sched->ops->run_job (s_job); + i++; + +if (IS_ERR_OR_NULL (fence)) {
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 435
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+if (IS_ERR (fence)) +dma_fence_set_error (&s_fence->finished,PTR_ERR (fence)); + + s_job->s_fence->parent =NULL ; + }else { + s_job->s_fence->parent = fence; + } + } +} +EXPORT_SYMBOL (drm_sched_resubmit_jobs2);
This is identical to drm_sched_resubmit_jobs in all but the 'int max' handling, can't you reuse drm_sched_resubmit_jobs by passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?
Quoted 26 lines
drivers/gpu/drm/scheduler/sched_main.c +26
-0+ + + +void drm_sched_reset_karma (struct drm_sched_job *bad) +{ +int i; +struct drm_sched_entity *tmp; +struct drm_sched_entity *entity; +struct drm_gpu_scheduler *sched = bad->sched; + +/* don't reset @bad's karma if it's from KERNEL RQ, +* because sometimes GPU hang would cause kernel jobs (like VM updating jobs) +* corrupt but keep in mind that kernel jobs always considered good. +*/ +if (bad->s_priority !=DRM_SCHED_PRIORITY_KERNEL ) { +atomic_set (&bad->karma,0 ); +for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_KERNEL ; + i++) { +struct drm_sched_rq *rq = &sched->sched_rq[i]; + +spin_lock (&rq->lock); +list_for_each_entry_safe (entity, tmp, &rq->entities, list) { +if (bad->s_fence->scheduled.context == + entity->fence_context) { +if (entity->guilty) +atomic_set (entity->guilty,0 );
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 471
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+break ; + } + } +spin_unlock (&rq->lock); +if (&entity->list != &rq->entities) +break ; + } + } +} +EXPORT_SYMBOL (drm_sched_reset_karma);
Same as above, very similar drm_sched_increase_karma, I would add a flag and just reuse code instead of duplucation.
Andrey
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0+/** * drm_sched_stop - stop the scheduler * include/drm/gpu_scheduler.h +0
-0
include/drm/gpu_scheduler.h void drm_sched_wakeup(struct drm_gpu_scheduler *sched); · line 329
Quoted 9 lines
include/drm/gpu_scheduler.h +2
-0@@ -321,7 +321,9 @@ void drm_sched_wakeup(struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched); +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int max);void drm_sched_increase_karma (struct drm_sched_job *bad); +void drm_sched_reset_karma (struct drm_sched_job *bad);bool drm_sched_dependency_optimized (struct dma_fence * fence,struct drm_sched_entity *entity);void drm_sched_fault (struct drm_gpu_scheduler *sched);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Hi, Andrey,
Thank you for your review.
Quoted 1 line
Quoted 1 line
This is identical to
drm_sched_resubmit_jobsin all but the 'int max' handling, can't you reusedrm_sched_resubmit_jobsby passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?
Due to C language doesn't support function overloading, we couldn’t define function like the following(compiler error):
void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max = INT_MAX);
We have to rewrite every vender's code where call the drm_sched_resubmit_jobs if we defined the function like this. void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max);
Meanwhile, I also explored the Variable Arguments in C, But it still cannot meet the needs very well.
Do you know some other methods that could help us to make this happen? Otherwise, I'm afraid we have to define a separate ways as patch V6 did.
Thanks,
Jack
-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: Thursday, March 11, 2021 12:19 AM
To: Zhang, Jack (Jian) <[email protected]>; [email protected]; Koenig, Christian <[email protected]>; Liu, Monk <[email protected]>; Deng, Emily <[email protected]>
Subject: Re: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
Quoted 47 lines · Jack Zhang
[Why]
Previous tdr design treats the first job injob_timeoutas the bad job. But sometimes a later bad compute job can block a good gfx job and cause an unexpected gfx job timeout because gfx and compute ring share internal GC HW mutually.[How]
This patch implements an advanced tdr mode.It involves an additinal synchronous pre-resubmit step(Step0 Resubmit) before normal resubmit step in order to find the real bad job.1. At Step0 Resubmit stage, it synchronously submits and pends for the first job being signaled. If it gets timeout, we identify it as guilty and do hw reset. After that, we would do the normal resubmit step to resubmit left jobs.
2. Re-insert Bailing job to
mirror_list, and leave it to be handled by the main reset thread.3. For whole gpu reset(vram lost), do resubmit as the old way.
Signed-off-by Jack Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 72 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 75 ++++++++++++++++++++++ include/drm/gpu_scheduler.h | 2 + 4 files changed, 148 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-2@@ -4639,6 +4639,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,int i, r =0 ;bool need_emergency_restart = false;bool audio_suspended = false; +int tmp_vram_lost_counter;/* * Special case: RAS triggered and full reset isn't supported @@ -4689,9 +4690,14 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, dev_info(adev->dev, "Bailing on TDR for s_job:%llx, as another already in progress", job ? job->base.id : -1); -/* even we skipped this reset, still need to set the job to guilty */
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-1-if (job) +if (job) { +/* re-insert node to avoid memory leak */ +spin_lock (&job->base.sched->job_list_lock); +list_add (&job->base.node, &job->base.sched->pending_list); +spin_unlock (&job->base.sched->job_list_lock); +/* even we skipped this reset, still need to set the job to guilty +*/ drm_sched_increase_karma (&job->base); +}
I think this piece should be in a standalone patch as it comes to fix a bug of leaking jobs and not directly related to find actual guilty job. Also, this is not the only place where the problem arises - it also arises in other drivers where they check that guilty job's fence already signaled and bail out before reinsertion of bad job to mirror list. Seems to me better fix would be to handle this within scheduler code by adding specific return value to drm_sched_backend_ops.timedout_job marking that the code terminated early - before calling drm_sched_stop and so drm_sched_job_timedout would know this and then reinsert the job back to mirror_list itself.
Quoted 134 lines
goto skip_recovery; }drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +64
-0@@ -4788,6 +4794,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, } } +tmp_vram_lost_counter =atomic_read (&((adev)->vram_lost_counter));/* Actual ASIC resets if needed.*/ /* TODO Implement XGMI hive reset logic for SRIOV */ if (amdgpu_sriov_vf (adev)) {@@ -4805,6 +4812,67 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,/* Post ASIC reset for all devs .*/ list_for_each_entry (tmp_adev, device_list_handle, gmc.xgmi.head) { +if (amdgpu_gpu_recovery ==2 && +!(tmp_vram_lost_counter <atomic_read (&adev->vram_lost_counter))) +{ + +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; +int ret =0 ; +struct drm_sched_job *s_job; + +if (!ring || !ring->sched.thread) +continue ; + +/* No point to resubmit jobs if we didn't HW reset*/ +if (!tmp_adev->asic_reset_res && !job_signaled) { + +s_job = list_first_entry_or_null(&ring->sched.pending_list, struct drm_sched_job, list); +if (s_job ==NULL ) +continue ; + +/* clear job's guilty and depend the folowing step to decide the real one */ +drm_sched_reset_karma (s_job); +drm_sched_resubmit_jobs2 (&ring->sched,1 ); +ret =dma_fence_wait_timeout (s_job->s_fence->parent, false, +ring->sched.timeout); + +if (ret ==0 ) {/* timeout */ +DRM_ERROR ("Found the real bad job! ring:%s, job_id:%llx\n" , ring->sched.name, s_job->id); +/* set guilty */ +drm_sched_increase_karma (s_job); + +/* do hw reset */ +if (amdgpu_sriov_vf (adev)) { +amdgpu_virt_fini_data_exchange (adev); +r =amdgpu_device_reset_sriov (adev, false); +if (r) +adev->asic_reset_res = r; +}else { +r =amdgpu_do_asic_reset (hive, device_list_handle, &need_full_reset, false); +if (r && r == -EAGAIN ) +goto retry; +} + +/* add reset counter so that the following resubmitted job could flush vmid */ +atomic_inc (&tmp_adev->gpu_reset_counter); +continue ; +} + +/* got the hw fence, signal finished fence */ +atomic_dec (&ring->sched.num_jobs); +dma_fence_get (&s_job->s_fence->finished); +dma_fence_signal (&s_job->s_fence->finished); +dma_fence_put (&s_job->s_fence->finished); + + +/* remove node from list and free the job */ +spin_lock (&ring->sched.job_list_lock); +list_del_init (&s_job->node); +spin_unlock (&ring->sched.job_list_lock); +ring->sched.ops->free_job (s_job); +} +} +} +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i];drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -509,7 +509,7 @@ module_param_named(compute_multipipe, amdgpu_compute_multipipe, int, 0444);* DOC: gpu_recovery (int) * Set to enable GPU recovery mechanism (1 = enable, 0 = disable). The default is -1 (auto, disabled except SRIOV). */ -MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (1 = enable, 0 = disable, -1 = auto)"); +MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (2 = +advanced tdr mode, 1 = enable, 0 = disable, -1 = auto)");module_param_named (gpu_recovery, amdgpu_gpu_recovery, int,0444 );/** drivers/gpu/drm/scheduler/sched_main.c +28
-0@@ -395,6 +395,81 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) }EXPORT_SYMBOL (drm_sched_increase_karma); + +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max) { +struct drm_sched_job *s_job, *tmp; +uint64_t guilty_context; +bool found_guilty = false; +struct dma_fence *fence; +int i =0 ; + +list_for_each_entry_safe(s_job, tmp, &sched->pending_list, list) { +struct drm_sched_fence *s_fence = s_job->s_fence; + +if (i >= max) +break ; + +if (!found_guilty &&atomic_read (&s_job->karma) > sched->hang_limit) { +found_guilty = true; +guilty_context = s_job->s_fence->scheduled.context; +} + +if (found_guilty && s_job->s_fence->scheduled.context == guilty_context) +dma_fence_set_error (&s_fence->finished, -ECANCELED ); + +dma_fence_put (s_job->s_fence->parent); +fence = sched->ops->run_job (s_job); +i++; + +if (IS_ERR_OR_NULL (fence)) {
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 435
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+if (IS_ERR (fence)) +dma_fence_set_error (&s_fence->finished,PTR_ERR (fence)); + +s_job->s_fence->parent =NULL ; +}else { +s_job->s_fence->parent = fence; +} +} +} +EXPORT_SYMBOL (drm_sched_resubmit_jobs2);
This is identical to drm_sched_resubmit_jobs in all but the 'int max' handling, can't you reuse drm_sched_resubmit_jobs by passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?
Quoted 25 lines
drivers/gpu/drm/scheduler/sched_main.c +25
-0+ + + +void drm_sched_reset_karma (struct drm_sched_job *bad) { +int i; +struct drm_sched_entity *tmp; +struct drm_sched_entity *entity; +struct drm_gpu_scheduler *sched = bad->sched; + +/* don't reset @bad's karma if it's from KERNEL RQ, +* because sometimes GPU hang would cause kernel jobs (like VM updating jobs) +* corrupt but keep in mind that kernel jobs always considered good. +*/ +if (bad->s_priority !=DRM_SCHED_PRIORITY_KERNEL ) { +atomic_set (&bad->karma,0 ); +for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_KERNEL ; + i++) { +struct drm_sched_rq *rq = &sched->sched_rq[i]; + +spin_lock (&rq->lock); +list_for_each_entry_safe(entity, tmp, &rq->entities, list) { +if (bad->s_fence->scheduled.context == +entity->fence_context) { +if (entity->guilty) +atomic_set (entity->guilty,0 );
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 471
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+break ; +} +} +spin_unlock (&rq->lock); +if (&entity->list != &rq->entities) +break ; +} +} +} +EXPORT_SYMBOL (drm_sched_reset_karma);
Same as above, very similar drm_sched_increase_karma, I would add a flag and just reuse code instead of duplucation.
Andrey
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0+/** * drm_sched_stop - stop the scheduler * include/drm/gpu_scheduler.h +0
-0
include/drm/gpu_scheduler.h void drm_sched_wakeup(struct drm_gpu_scheduler *sched); · line 329
Quoted 10 lines
include/drm/gpu_scheduler.h +3
-0@@ -321,7 +321,9 @@ void drm_sched_wakeup(struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched); +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max);void drm_sched_increase_karma (struct drm_sched_job *bad); +void drm_sched_reset_karma (struct drm_sched_job *bad);bool drm_sched_dependency_optimized (struct dma_fence * fence,struct drm_sched_entity *entity);void drm_sched_fault (struct drm_gpu_scheduler *sched);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
You can just rename drm_sched_resubmit_jobs to drm_sched_resubmit_jobs_imp and create a wrapper function drm_sched_resubmit_jobs which will call that function with MAX_INT and so no need for code change in other driver will be needed. For amdgpu you call directly drm_sched_resubmit_jobs_imp with 1 and MAX_INT.
Andrey
________________________________
From: Zhang, Jack (Jian) <[email protected]>
Sent: 10 March 2021 22:05
To: Grodzovsky, Andrey <[email protected]>; [email protected] <[email protected]>; Koenig, Christian <[email protected]>; Liu, Monk <[email protected]>; Deng, Emily <[email protected]>
Subject: RE: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
[AMD Official Use Only - Internal Distribution Only]
Hi, Andrey,
Thank you for your review.
Quoted 1 line
Quoted 1 line
This is identical to
drm_sched_resubmit_jobsin all but the 'int max' handling, can't you reusedrm_sched_resubmit_jobsby passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?
Due to C language doesn't support function overloading, we couldn’t define function like the following(compiler error):
void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max = INT_MAX);
We have to rewrite every vender's code where call the drm_sched_resubmit_jobs if we defined the function like this. void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max);
Meanwhile, I also explored the Variable Arguments in C, But it still cannot meet the needs very well.
Do you know some other methods that could help us to make this happen? Otherwise, I'm afraid we have to define a separate ways as patch V6 did.
Thanks,
Jack
-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: Thursday, March 11, 2021 12:19 AM
To: Zhang, Jack (Jian) <[email protected]>; [email protected]; Koenig, Christian <[email protected]>; Liu, Monk <[email protected]>; Deng, Emily <[email protected]>
Subject: Re: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
Quoted 47 lines · Jack Zhang
[Why]
Previous tdr design treats the first job injob_timeoutas the bad job. But sometimes a later bad compute job can block a good gfx job and cause an unexpected gfx job timeout because gfx and compute ring share internal GC HW mutually.[How]
This patch implements an advanced tdr mode.It involves an additinal synchronous pre-resubmit step(Step0 Resubmit) before normal resubmit step in order to find the real bad job.1. At Step0 Resubmit stage, it synchronously submits and pends for the first job being signaled. If it gets timeout, we identify it as guilty and do hw reset. After that, we would do the normal resubmit step to resubmit left jobs.
2. Re-insert Bailing job to
mirror_list, and leave it to be handled by the main reset thread.3. For whole gpu reset(vram lost), do resubmit as the old way.
Signed-off-by Jack Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 72 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 75 ++++++++++++++++++++++ include/drm/gpu_scheduler.h | 2 + 4 files changed, 148 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-2@@ -4639,6 +4639,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,int i, r =0 ;bool need_emergency_restart = false;bool audio_suspended = false; +int tmp_vram_lost_counter;/* * Special case: RAS triggered and full reset isn't supported @@ -4689,9 +4690,14 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, dev_info(adev->dev, "Bailing on TDR for s_job:%llx, as another already in progress", job ? job->base.id : -1); -/* even we skipped this reset, still need to set the job to guilty */
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-1-if (job) +if (job) { +/* re-insert node to avoid memory leak */ +spin_lock (&job->base.sched->job_list_lock); +list_add (&job->base.node, &job->base.sched->pending_list); +spin_unlock (&job->base.sched->job_list_lock); +/* even we skipped this reset, still need to set the job to guilty +*/ drm_sched_increase_karma (&job->base); +}
I think this piece should be in a standalone patch as it comes to fix a bug of leaking jobs and not directly related to find actual guilty job. Also, this is not the only place where the problem arises - it also arises in other drivers where they check that guilty job's fence already signaled and bail out before reinsertion of bad job to mirror list. Seems to me better fix would be to handle this within scheduler code by adding specific return value to drm_sched_backend_ops.timedout_job marking that the code terminated early - before calling drm_sched_stop and so drm_sched_job_timedout would know this and then reinsert the job back to mirror_list itself.
Quoted 134 lines
goto skip_recovery; }drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +64
-0@@ -4788,6 +4794,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, } } +tmp_vram_lost_counter =atomic_read (&((adev)->vram_lost_counter));/* Actual ASIC resets if needed.*/ /* TODO Implement XGMI hive reset logic for SRIOV */ if (amdgpu_sriov_vf (adev)) {@@ -4805,6 +4812,67 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,/* Post ASIC reset for all devs .*/ list_for_each_entry (tmp_adev, device_list_handle, gmc.xgmi.head) { +if (amdgpu_gpu_recovery ==2 && +!(tmp_vram_lost_counter <atomic_read (&adev->vram_lost_counter))) +{ + +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; +int ret =0 ; +struct drm_sched_job *s_job; + +if (!ring || !ring->sched.thread) +continue ; + +/* No point to resubmit jobs if we didn't HW reset*/ +if (!tmp_adev->asic_reset_res && !job_signaled) { + +s_job = list_first_entry_or_null(&ring->sched.pending_list, struct drm_sched_job, list); +if (s_job ==NULL ) +continue ; + +/* clear job's guilty and depend the folowing step to decide the real one */ +drm_sched_reset_karma (s_job); +drm_sched_resubmit_jobs2 (&ring->sched,1 ); +ret =dma_fence_wait_timeout (s_job->s_fence->parent, false, +ring->sched.timeout); + +if (ret ==0 ) {/* timeout */ +DRM_ERROR ("Found the real bad job! ring:%s, job_id:%llx\n" , ring->sched.name, s_job->id); +/* set guilty */ +drm_sched_increase_karma (s_job); + +/* do hw reset */ +if (amdgpu_sriov_vf (adev)) { +amdgpu_virt_fini_data_exchange (adev); +r =amdgpu_device_reset_sriov (adev, false); +if (r) +adev->asic_reset_res = r; +}else { +r =amdgpu_do_asic_reset (hive, device_list_handle, &need_full_reset, false); +if (r && r == -EAGAIN ) +goto retry; +} + +/* add reset counter so that the following resubmitted job could flush vmid */ +atomic_inc (&tmp_adev->gpu_reset_counter); +continue ; +} + +/* got the hw fence, signal finished fence */ +atomic_dec (&ring->sched.num_jobs); +dma_fence_get (&s_job->s_fence->finished); +dma_fence_signal (&s_job->s_fence->finished); +dma_fence_put (&s_job->s_fence->finished); + + +/* remove node from list and free the job */ +spin_lock (&ring->sched.job_list_lock); +list_del_init (&s_job->node); +spin_unlock (&ring->sched.job_list_lock); +ring->sched.ops->free_job (s_job); +} +} +} +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i];drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -509,7 +509,7 @@ module_param_named(compute_multipipe, amdgpu_compute_multipipe, int, 0444);* DOC: gpu_recovery (int) * Set to enable GPU recovery mechanism (1 = enable, 0 = disable). The default is -1 (auto, disabled except SRIOV). */ -MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (1 = enable, 0 = disable, -1 = auto)"); +MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (2 = +advanced tdr mode, 1 = enable, 0 = disable, -1 = auto)");module_param_named (gpu_recovery, amdgpu_gpu_recovery, int,0444 );/** drivers/gpu/drm/scheduler/sched_main.c +28
-0@@ -395,6 +395,81 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) }EXPORT_SYMBOL (drm_sched_increase_karma); + +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max) { +struct drm_sched_job *s_job, *tmp; +uint64_t guilty_context; +bool found_guilty = false; +struct dma_fence *fence; +int i =0 ; + +list_for_each_entry_safe(s_job, tmp, &sched->pending_list, list) { +struct drm_sched_fence *s_fence = s_job->s_fence; + +if (i >= max) +break ; + +if (!found_guilty &&atomic_read (&s_job->karma) > sched->hang_limit) { +found_guilty = true; +guilty_context = s_job->s_fence->scheduled.context; +} + +if (found_guilty && s_job->s_fence->scheduled.context == guilty_context) +dma_fence_set_error (&s_fence->finished, -ECANCELED ); + +dma_fence_put (s_job->s_fence->parent); +fence = sched->ops->run_job (s_job); +i++; + +if (IS_ERR_OR_NULL (fence)) {
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 435
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+if (IS_ERR (fence)) +dma_fence_set_error (&s_fence->finished,PTR_ERR (fence)); + +s_job->s_fence->parent =NULL ; +}else { +s_job->s_fence->parent = fence; +} +} +} +EXPORT_SYMBOL (drm_sched_resubmit_jobs2);
This is identical to drm_sched_resubmit_jobs in all but the 'int max' handling, can't you reuse drm_sched_resubmit_jobs by passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?
Quoted 25 lines
drivers/gpu/drm/scheduler/sched_main.c +25
-0+ + + +void drm_sched_reset_karma (struct drm_sched_job *bad) { +int i; +struct drm_sched_entity *tmp; +struct drm_sched_entity *entity; +struct drm_gpu_scheduler *sched = bad->sched; + +/* don't reset @bad's karma if it's from KERNEL RQ, +* because sometimes GPU hang would cause kernel jobs (like VM updating jobs) +* corrupt but keep in mind that kernel jobs always considered good. +*/ +if (bad->s_priority !=DRM_SCHED_PRIORITY_KERNEL ) { +atomic_set (&bad->karma,0 ); +for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_KERNEL ; + i++) { +struct drm_sched_rq *rq = &sched->sched_rq[i]; + +spin_lock (&rq->lock); +list_for_each_entry_safe(entity, tmp, &rq->entities, list) { +if (bad->s_fence->scheduled.context == +entity->fence_context) { +if (entity->guilty) +atomic_set (entity->guilty,0 );
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 471
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+break ; +} +} +spin_unlock (&rq->lock); +if (&entity->list != &rq->entities) +break ; +} +} +} +EXPORT_SYMBOL (drm_sched_reset_karma);
Same as above, very similar drm_sched_increase_karma, I would add a flag and just reuse code instead of duplucation.
Andrey
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0+/** * drm_sched_stop - stop the scheduler * include/drm/gpu_scheduler.h +0
-0
include/drm/gpu_scheduler.h void drm_sched_wakeup(struct drm_gpu_scheduler *sched); · line 329
Quoted 10 lines
include/drm/gpu_scheduler.h +3
-0@@ -321,7 +321,9 @@ void drm_sched_wakeup(struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched); +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max);void drm_sched_increase_karma (struct drm_sched_job *bad); +void drm_sched_reset_karma (struct drm_sched_job *bad);bool drm_sched_dependency_optimized (struct dma_fence * fence,struct drm_sched_entity *entity);void drm_sched_fault (struct drm_gpu_scheduler *sched);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Ok, that will do the trick. Thank you!
Jack
From: Grodzovsky, Andrey <[email protected]>
Sent: Thursday, March 11, 2021 11:24 AM
To: Zhang, Jack (Jian) <[email protected]>; [email protected]; Koenig, Christian <[email protected]>; Liu, Monk <[email protected]>; Deng, Emily <[email protected]>
Subject: Re: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
You can just rename drm_sched_resubmit_jobs to drm_sched_resubmit_jobs_imp and create a wrapper function drm_sched_resubmit_jobs which will call that function with MAX_INT and so no need for code change in other driver will be needed. For amdgpu you call directly drm_sched_resubmit_jobs_imp with 1 and MAX_INT.
Andrey
________________________________
From: Zhang, Jack (Jian) <[email protected]<mailto:[email protected]>>
Sent: 10 March 2021 22:05
To: Grodzovsky, Andrey <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>; Koenig, Christian <[email protected]<mailto:[email protected]>>; Liu, Monk <[email protected]<mailto:[email protected]>>; Deng, Emily <[email protected]<mailto:[email protected]>>
Subject: RE: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
[AMD Official Use Only - Internal Distribution Only]
Hi, Andrey,
Thank you for your review.
Quoted 1 line
Quoted 1 line
This is identical to
drm_sched_resubmit_jobsin all but the 'int max' handling, can't you reusedrm_sched_resubmit_jobsby passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?
Due to C language doesn't support function overloading, we couldn’t define function like the following(compiler error):
void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max = INT_MAX);
We have to rewrite every vender's code where call the drm_sched_resubmit_jobs if we defined the function like this. void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max);
Meanwhile, I also explored the Variable Arguments in C, But it still cannot meet the needs very well.
Do you know some other methods that could help us to make this happen? Otherwise, I'm afraid we have to define a separate ways as patch V6 did.
Thanks,
Jack
-----Original Message-----
From: Grodzovsky, Andrey <[email protected]<mailto:[email protected]>>
Sent: Thursday, March 11, 2021 12:19 AM
To: Zhang, Jack (Jian) <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>; Koenig, Christian <[email protected]<mailto:[email protected]>>; Liu, Monk <[email protected]<mailto:[email protected]>>; Deng, Emily <[email protected]<mailto:[email protected]>>
Subject: Re: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
Quoted 47 lines · Jack Zhang
[Why]
Previous tdr design treats the first job injob_timeoutas the bad job. But sometimes a later bad compute job can block a good gfx job and cause an unexpected gfx job timeout because gfx and compute ring share internal GC HW mutually.[How]
This patch implements an advanced tdr mode.It involves an additinal synchronous pre-resubmit step(Step0 Resubmit) before normal resubmit step in order to find the real bad job.1. At Step0 Resubmit stage, it synchronously submits and pends for the first job being signaled. If it gets timeout, we identify it as guilty and do hw reset. After that, we would do the normal resubmit step to resubmit left jobs.
2. Re-insert Bailing job to
mirror_list, and leave it to be handled by the main reset thread.3. For whole gpu reset(vram lost), do resubmit as the old way.
Signed-off-by Jack Zhang <[email protected]<mailto:[email protected]>>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 72 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 75 ++++++++++++++++++++++ include/drm/gpu_scheduler.h | 2 + 4 files changed, 148 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-2@@ -4639,6 +4639,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,int i, r =0 ;bool need_emergency_restart = false;bool audio_suspended = false; +int tmp_vram_lost_counter;/* * Special case: RAS triggered and full reset isn't supported @@ -4689,9 +4690,14 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, dev_info(adev->dev, "Bailing on TDR for s_job:%llx, as another already in progress", job ? job->base.id : -1); -/* even we skipped this reset, still need to set the job to guilty */
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-1-if (job) +if (job) { +/* re-insert node to avoid memory leak */ +spin_lock (&job->base.sched->job_list_lock); +list_add (&job->base.node, &job->base.sched->pending_list); +spin_unlock (&job->base.sched->job_list_lock); +/* even we skipped this reset, still need to set the job to guilty +*/ drm_sched_increase_karma (&job->base); +}
I think this piece should be in a standalone patch as it comes to fix a bug of leaking jobs and not directly related to find actual guilty job. Also, this is not the only place where the problem arises - it also arises in other drivers where they check that guilty job's fence already signaled and bail out before reinsertion of bad job to mirror list. Seems to me better fix would be to handle this within scheduler code by adding specific return value to drm_sched_backend_ops.timedout_job marking that the code terminated early - before calling drm_sched_stop and so drm_sched_job_timedout would know this and then reinsert the job back to mirror_list itself.
Quoted 134 lines
goto skip_recovery; }drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +64
-0@@ -4788,6 +4794,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, } } +tmp_vram_lost_counter =atomic_read (&((adev)->vram_lost_counter));/* Actual ASIC resets if needed.*/ /* TODO Implement XGMI hive reset logic for SRIOV */ if (amdgpu_sriov_vf (adev)) {@@ -4805,6 +4812,67 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,/* Post ASIC reset for all devs .*/ list_for_each_entry (tmp_adev, device_list_handle, gmc.xgmi.head) { +if (amdgpu_gpu_recovery ==2 && +!(tmp_vram_lost_counter <atomic_read (&adev->vram_lost_counter))) +{ + +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; +int ret =0 ; +struct drm_sched_job *s_job; + +if (!ring || !ring->sched.thread) +continue ; + +/* No point to resubmit jobs if we didn't HW reset*/ +if (!tmp_adev->asic_reset_res && !job_signaled) { + +s_job = list_first_entry_or_null(&ring->sched.pending_list, struct drm_sched_job, list); +if (s_job ==NULL ) +continue ; + +/* clear job's guilty and depend the folowing step to decide the real one */ +drm_sched_reset_karma (s_job); +drm_sched_resubmit_jobs2 (&ring->sched,1 ); +ret =dma_fence_wait_timeout (s_job->s_fence->parent, false, +ring->sched.timeout); + +if (ret ==0 ) {/* timeout */ +DRM_ERROR ("Found the real bad job! ring:%s, job_id:%llx\n" , ring->sched.name, s_job->id); +/* set guilty */ +drm_sched_increase_karma (s_job); + +/* do hw reset */ +if (amdgpu_sriov_vf (adev)) { +amdgpu_virt_fini_data_exchange (adev); +r =amdgpu_device_reset_sriov (adev, false); +if (r) +adev->asic_reset_res = r; +}else { +r =amdgpu_do_asic_reset (hive, device_list_handle, &need_full_reset, false); +if (r && r == -EAGAIN ) +goto retry; +} + +/* add reset counter so that the following resubmitted job could flush vmid */ +atomic_inc (&tmp_adev->gpu_reset_counter); +continue ; +} + +/* got the hw fence, signal finished fence */ +atomic_dec (&ring->sched.num_jobs); +dma_fence_get (&s_job->s_fence->finished); +dma_fence_signal (&s_job->s_fence->finished); +dma_fence_put (&s_job->s_fence->finished); + + +/* remove node from list and free the job */ +spin_lock (&ring->sched.job_list_lock); +list_del_init (&s_job->node); +spin_unlock (&ring->sched.job_list_lock); +ring->sched.ops->free_job (s_job); +} +} +} +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i];drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -509,7 +509,7 @@ module_param_named(compute_multipipe, amdgpu_compute_multipipe, int, 0444);* DOC: gpu_recovery (int) * Set to enable GPU recovery mechanism (1 = enable, 0 = disable). The default is -1 (auto, disabled except SRIOV). */ -MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (1 = enable, 0 = disable, -1 = auto)"); +MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (2 = +advanced tdr mode, 1 = enable, 0 = disable, -1 = auto)");module_param_named (gpu_recovery, amdgpu_gpu_recovery, int,0444 );/** drivers/gpu/drm/scheduler/sched_main.c +28
-0@@ -395,6 +395,81 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) }EXPORT_SYMBOL (drm_sched_increase_karma); + +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max) { +struct drm_sched_job *s_job, *tmp; +uint64_t guilty_context; +bool found_guilty = false; +struct dma_fence *fence; +int i =0 ; + +list_for_each_entry_safe(s_job, tmp, &sched->pending_list, list) { +struct drm_sched_fence *s_fence = s_job->s_fence; + +if (i >= max) +break ; + +if (!found_guilty &&atomic_read (&s_job->karma) > sched->hang_limit) { +found_guilty = true; +guilty_context = s_job->s_fence->scheduled.context; +} + +if (found_guilty && s_job->s_fence->scheduled.context == guilty_context) +dma_fence_set_error (&s_fence->finished, -ECANCELED ); + +dma_fence_put (s_job->s_fence->parent); +fence = sched->ops->run_job (s_job); +i++; + +if (IS_ERR_OR_NULL (fence)) {
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 435
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+if (IS_ERR (fence)) +dma_fence_set_error (&s_fence->finished,PTR_ERR (fence)); + +s_job->s_fence->parent =NULL ; +}else { +s_job->s_fence->parent = fence; +} +} +} +EXPORT_SYMBOL (drm_sched_resubmit_jobs2);
This is identical to drm_sched_resubmit_jobs in all but the 'int max' handling, can't you reuse drm_sched_resubmit_jobs by passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?
Quoted 25 lines
drivers/gpu/drm/scheduler/sched_main.c +25
-0+ + + +void drm_sched_reset_karma (struct drm_sched_job *bad) { +int i; +struct drm_sched_entity *tmp; +struct drm_sched_entity *entity; +struct drm_gpu_scheduler *sched = bad->sched; + +/* don't reset @bad's karma if it's from KERNEL RQ, +* because sometimes GPU hang would cause kernel jobs (like VM updating jobs) +* corrupt but keep in mind that kernel jobs always considered good. +*/ +if (bad->s_priority !=DRM_SCHED_PRIORITY_KERNEL ) { +atomic_set (&bad->karma,0 ); +for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_KERNEL ; + i++) { +struct drm_sched_rq *rq = &sched->sched_rq[i]; + +spin_lock (&rq->lock); +list_for_each_entry_safe(entity, tmp, &rq->entities, list) { +if (bad->s_fence->scheduled.context == +entity->fence_context) { +if (entity->guilty) +atomic_set (entity->guilty,0 );
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 471
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+break ; +} +} +spin_unlock (&rq->lock); +if (&entity->list != &rq->entities) +break ; +} +} +} +EXPORT_SYMBOL (drm_sched_reset_karma);
Same as above, very similar drm_sched_increase_karma, I would add a flag and just reuse code instead of duplucation.
Andrey
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0+/** * drm_sched_stop - stop the scheduler * include/drm/gpu_scheduler.h +0
-0
include/drm/gpu_scheduler.h void drm_sched_wakeup(struct drm_gpu_scheduler *sched); · line 329
Quoted 10 lines
include/drm/gpu_scheduler.h +3
-0@@ -321,7 +321,9 @@ void drm_sched_wakeup(struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched); +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max);void drm_sched_increase_karma (struct drm_sched_job *bad); +void drm_sched_reset_karma (struct drm_sched_job *bad);bool drm_sched_dependency_optimized (struct dma_fence * fence,struct drm_sched_entity *entity);void drm_sched_fault (struct drm_gpu_scheduler *sched);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[AMD Official Use Only - Internal Distribution Only]
Hi, Andrey,
I just submitted the V7 patch in which I wrapped the increase_karma func and resubmit_job func.
Thanks,
Jack
From: amd-gfx <[email protected]> On Behalf Of Zhang, Jack (Jian)
Sent: Thursday, March 11, 2021 11:28 AM
To: Grodzovsky, Andrey <[email protected]>; [email protected]; Koenig, Christian <[email protected]>; Liu, Monk <[email protected]>; Deng, Emily <[email protected]>
Subject: RE: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
[AMD Official Use Only - Internal Distribution Only]
[AMD Official Use Only - Internal Distribution Only]
Ok, that will do the trick. Thank you!
Jack
From: Grodzovsky, Andrey <[email protected]<mailto:[email protected]>>
Sent: Thursday, March 11, 2021 11:24 AM
To: Zhang, Jack (Jian) <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>; Koenig, Christian <[email protected]<mailto:[email protected]>>; Liu, Monk <[email protected]<mailto:[email protected]>>; Deng, Emily <[email protected]<mailto:[email protected]>>
Subject: Re: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
You can just rename drm_sched_resubmit_jobs to drm_sched_resubmit_jobs_imp and create a wrapper function drm_sched_resubmit_jobs which will call that function with MAX_INT and so no need for code change in other driver will be needed. For amdgpu you call directly drm_sched_resubmit_jobs_imp with 1 and MAX_INT.
Andrey
________________________________
From: Zhang, Jack (Jian) <[email protected]<mailto:[email protected]>>
Sent: 10 March 2021 22:05
To: Grodzovsky, Andrey <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>; Koenig, Christian <[email protected]<mailto:[email protected]>>; Liu, Monk <[email protected]<mailto:[email protected]>>; Deng, Emily <[email protected]<mailto:[email protected]>>
Subject: RE: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
[AMD Official Use Only - Internal Distribution Only]
Hi, Andrey,
Thank you for your review.
Quoted 1 line
Quoted 1 line
This is identical to
drm_sched_resubmit_jobsin all but the 'int max' handling, can't you reusedrm_sched_resubmit_jobsby passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?
Due to C language doesn't support function overloading, we couldn’t define function like the following(compiler error):
void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max = INT_MAX);
We have to rewrite every vender's code where call the drm_sched_resubmit_jobs if we defined the function like this. void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max);
Meanwhile, I also explored the Variable Arguments in C, But it still cannot meet the needs very well.
Do you know some other methods that could help us to make this happen? Otherwise, I'm afraid we have to define a separate ways as patch V6 did.
Thanks,
Jack
-----Original Message-----
From: Grodzovsky, Andrey <[email protected]<mailto:[email protected]>>
Sent: Thursday, March 11, 2021 12:19 AM
To: Zhang, Jack (Jian) <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>; Koenig, Christian <[email protected]<mailto:[email protected]>>; Liu, Monk <[email protected]<mailto:[email protected]>>; Deng, Emily <[email protected]<mailto:[email protected]>>
Subject: Re: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
Quoted 47 lines · Jack Zhang
[Why]
Previous tdr design treats the first job injob_timeoutas the bad job. But sometimes a later bad compute job can block a good gfx job and cause an unexpected gfx job timeout because gfx and compute ring share internal GC HW mutually.[How]
This patch implements an advanced tdr mode.It involves an additinal synchronous pre-resubmit step(Step0 Resubmit) before normal resubmit step in order to find the real bad job.1. At Step0 Resubmit stage, it synchronously submits and pends for the first job being signaled. If it gets timeout, we identify it as guilty and do hw reset. After that, we would do the normal resubmit step to resubmit left jobs.
2. Re-insert Bailing job to
mirror_list, and leave it to be handled by the main reset thread.3. For whole gpu reset(vram lost), do resubmit as the old way.
Signed-off-by Jack Zhang <[email protected]<mailto:[email protected]>>--- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 72 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 75 ++++++++++++++++++++++ include/drm/gpu_scheduler.h | 2 + 4 files changed, 148 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-2@@ -4639,6 +4639,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,int i, r =0 ;bool need_emergency_restart = false;bool audio_suspended = false; +int tmp_vram_lost_counter;/* * Special case: RAS triggered and full reset isn't supported @@ -4689,9 +4690,14 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, dev_info(adev->dev, "Bailing on TDR for s_job:%llx, as another already in progress", job ? job->base.id : -1); -/* even we skipped this reset, still need to set the job to guilty */
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +8
-1-if (job) +if (job) { +/* re-insert node to avoid memory leak */ +spin_lock (&job->base.sched->job_list_lock); +list_add (&job->base.node, &job->base.sched->pending_list); +spin_unlock (&job->base.sched->job_list_lock); +/* even we skipped this reset, still need to set the job to guilty +*/ drm_sched_increase_karma (&job->base); +}
I think this piece should be in a standalone patch as it comes to fix a bug of leaking jobs and not directly related to find actual guilty job. Also, this is not the only place where the problem arises - it also arises in other drivers where they check that guilty job's fence already signaled and bail out before reinsertion of bad job to mirror list. Seems to me better fix would be to handle this within scheduler code by adding specific return value to drm_sched_backend_ops.timedout_job marking that the code terminated early - before calling drm_sched_stop and so drm_sched_job_timedout would know this and then reinsert the job back to mirror_list itself.
Quoted 134 lines
goto skip_recovery; }drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +64
-0@@ -4788,6 +4794,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev, } } +tmp_vram_lost_counter =atomic_read (&((adev)->vram_lost_counter));/* Actual ASIC resets if needed.*/ /* TODO Implement XGMI hive reset logic for SRIOV */ if (amdgpu_sriov_vf (adev)) {@@ -4805,6 +4812,67 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,/* Post ASIC reset for all devs .*/ list_for_each_entry (tmp_adev, device_list_handle, gmc.xgmi.head) { +if (amdgpu_gpu_recovery ==2 && +!(tmp_vram_lost_counter <atomic_read (&adev->vram_lost_counter))) +{ + +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i]; +int ret =0 ; +struct drm_sched_job *s_job; + +if (!ring || !ring->sched.thread) +continue ; + +/* No point to resubmit jobs if we didn't HW reset*/ +if (!tmp_adev->asic_reset_res && !job_signaled) { + +s_job = list_first_entry_or_null(&ring->sched.pending_list, struct drm_sched_job, list); +if (s_job ==NULL ) +continue ; + +/* clear job's guilty and depend the folowing step to decide the real one */ +drm_sched_reset_karma (s_job); +drm_sched_resubmit_jobs2 (&ring->sched,1 ); +ret =dma_fence_wait_timeout (s_job->s_fence->parent, false, +ring->sched.timeout); + +if (ret ==0 ) {/* timeout */ +DRM_ERROR ("Found the real bad job! ring:%s, job_id:%llx\n" , ring->sched.name, s_job->id); +/* set guilty */ +drm_sched_increase_karma (s_job); + +/* do hw reset */ +if (amdgpu_sriov_vf (adev)) { +amdgpu_virt_fini_data_exchange (adev); +r =amdgpu_device_reset_sriov (adev, false); +if (r) +adev->asic_reset_res = r; +}else { +r =amdgpu_do_asic_reset (hive, device_list_handle, &need_full_reset, false); +if (r && r == -EAGAIN ) +goto retry; +} + +/* add reset counter so that the following resubmitted job could flush vmid */ +atomic_inc (&tmp_adev->gpu_reset_counter); +continue ; +} + +/* got the hw fence, signal finished fence */ +atomic_dec (&ring->sched.num_jobs); +dma_fence_get (&s_job->s_fence->finished); +dma_fence_signal (&s_job->s_fence->finished); +dma_fence_put (&s_job->s_fence->finished); + + +/* remove node from list and free the job */ +spin_lock (&ring->sched.job_list_lock); +list_del_init (&s_job->node); +spin_unlock (&ring->sched.job_list_lock); +ring->sched.ops->free_job (s_job); +} +} +} +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) {struct amdgpu_ring *ring = tmp_adev->rings[i];drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1@@ -509,7 +509,7 @@ module_param_named(compute_multipipe, amdgpu_compute_multipipe, int, 0444);* DOC: gpu_recovery (int) * Set to enable GPU recovery mechanism (1 = enable, 0 = disable). The default is -1 (auto, disabled except SRIOV). */ -MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (1 = enable, 0 = disable, -1 = auto)"); +MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (2 = +advanced tdr mode, 1 = enable, 0 = disable, -1 = auto)");module_param_named (gpu_recovery, amdgpu_gpu_recovery, int,0444 );/** drivers/gpu/drm/scheduler/sched_main.c +28
-0@@ -395,6 +395,81 @@ void drm_sched_increase_karma(struct drm_sched_job *bad) }EXPORT_SYMBOL (drm_sched_increase_karma); + +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max) { +struct drm_sched_job *s_job, *tmp; +uint64_t guilty_context; +bool found_guilty = false; +struct dma_fence *fence; +int i =0 ; + +list_for_each_entry_safe(s_job, tmp, &sched->pending_list, list) { +struct drm_sched_fence *s_fence = s_job->s_fence; + +if (i >= max) +break ; + +if (!found_guilty &&atomic_read (&s_job->karma) > sched->hang_limit) { +found_guilty = true; +guilty_context = s_job->s_fence->scheduled.context; +} + +if (found_guilty && s_job->s_fence->scheduled.context == guilty_context) +dma_fence_set_error (&s_fence->finished, -ECANCELED ); + +dma_fence_put (s_job->s_fence->parent); +fence = sched->ops->run_job (s_job); +i++; + +if (IS_ERR_OR_NULL (fence)) {
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 435
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+if (IS_ERR (fence)) +dma_fence_set_error (&s_fence->finished,PTR_ERR (fence)); + +s_job->s_fence->parent =NULL ; +}else { +s_job->s_fence->parent = fence; +} +} +} +EXPORT_SYMBOL (drm_sched_resubmit_jobs2);
This is identical to drm_sched_resubmit_jobs in all but the 'int max' handling, can't you reuse drm_sched_resubmit_jobs by passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?
Quoted 25 lines
drivers/gpu/drm/scheduler/sched_main.c +25
-0+ + + +void drm_sched_reset_karma (struct drm_sched_job *bad) { +int i; +struct drm_sched_entity *tmp; +struct drm_sched_entity *entity; +struct drm_gpu_scheduler *sched = bad->sched; + +/* don't reset @bad's karma if it's from KERNEL RQ, +* because sometimes GPU hang would cause kernel jobs (like VM updating jobs) +* corrupt but keep in mind that kernel jobs always considered good. +*/ +if (bad->s_priority !=DRM_SCHED_PRIORITY_KERNEL ) { +atomic_set (&bad->karma,0 ); +for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_KERNEL ; + i++) { +struct drm_sched_rq *rq = &sched->sched_rq[i]; + +spin_lock (&rq->lock); +list_for_each_entry_safe(entity, tmp, &rq->entities, list) { +if (bad->s_fence->scheduled.context == +entity->fence_context) { +if (entity->guilty) +atomic_set (entity->guilty,0 );
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 471
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+break ; +} +} +spin_unlock (&rq->lock); +if (&entity->list != &rq->entities) +break ; +} +} +} +EXPORT_SYMBOL (drm_sched_reset_karma);
Same as above, very similar drm_sched_increase_karma, I would add a flag and just reuse code instead of duplucation.
Andrey
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0+/** * drm_sched_stop - stop the scheduler * include/drm/gpu_scheduler.h +0
-0
include/drm/gpu_scheduler.h void drm_sched_wakeup(struct drm_gpu_scheduler *sched); · line 329
Quoted 10 lines
include/drm/gpu_scheduler.h +3
-0@@ -321,7 +321,9 @@ void drm_sched_wakeup(struct drm_gpu_scheduler *sched);void drm_sched_stop (struct drm_gpu_scheduler *sched,struct drm_sched_job *bad);void drm_sched_start (struct drm_gpu_scheduler *sched,bool full_recovery);void drm_sched_resubmit_jobs (struct drm_gpu_scheduler *sched); +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max);void drm_sched_increase_karma (struct drm_sched_job *bad); +void drm_sched_reset_karma (struct drm_sched_job *bad);bool drm_sched_dependency_optimized (struct dma_fence * fence,struct drm_sched_entity *entity);void drm_sched_fault (struct drm_gpu_scheduler *sched);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Christian König
maintainerAlternatively changing all callers to give MAX_INT as parameter when they don't care is the preferred variant, but a bit more work.
Christian.
Am 11.03.21 um 04:24 schrieb Grodzovsky, Andrey:
Quoted 317 lines
You can just rename
drm_sched_resubmit_jobstodrm_sched_resubmit_jobs_impand create a wrapperfunctiondrm_sched_resubmit_jobswhich will call that function withMAX_INTand so no need for code change in other driver will be needed. For amdgpu you call directlydrm_sched_resubmit_jobs_impwith 1 andMAX_INT.Andrey
------------------------------------------------------------------------
*From:* Zhang, Jack (Jian) <[email protected]>
*Sent:* 10 March 2021 22:05
*To:* Grodzovsky, Andrey <[email protected]>; [email protected] <[email protected]>; Koenig, Christian <[email protected]>; Liu, Monk <[email protected]>; Deng, Emily <[email protected]> *Subject:* RE: [PATCH v6] drm/amd/amdgpu implement tdr advanced mode
[AMD Official Use Only - Internal Distribution Only]Hi, Andrey,
Thank you for your review.
Quoted 1 line
Quoted 1 line
This is identical to
drm_sched_resubmit_jobsin all but the 'intmax' handling, can't you reuse
drm_sched_resubmit_jobsby passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?Due to C language doesn't support function overloading, we couldn’t define function like the following(compiler error):
voiddrm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max = INT_MAX);We have to rewrite every vender's code where call the
drm_sched_resubmit_jobsif we defined the function like this. voiddrm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched, int max);Meanwhile, I also explored the Variable Arguments in C, But it still cannot meet the needs very well.
Do you know some other methods that could help us to make this happen? Otherwise, I'm afraid we have to define a separate ways as patch V6 did.
Thanks,
Jack-----Original Message-----
From: Grodzovsky, Andrey <[email protected]>
Sent: Thursday, March 11, 2021 12:19 AM
To: Zhang, Jack (Jian) <[email protected]>; [email protected]; Koenig, Christian <[email protected]>; Liu, Monk <[email protected]>; Deng, Emily <[email protected]>
Subject: Re: [PATCH v6] drm/amd/amdgpu implement tdr advanced modedrivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct
Quoted 35 lines · Jack Zhang
[Why]
Previous tdr design treats the first job injob_timeoutas the bad job. But sometimes a later bad compute job can block a good gfx job and cause an unexpected gfx job timeout because gfx and compute ring share internal GC HW mutually.[How]
This patch implements an advanced tdr mode.It involves an additinal synchronous pre-resubmit step(Step0 Resubmit) before normal resubmit step in order to find the real bad job.1. At Step0 Resubmit stage, it synchronously submits and pends for the first job being signaled. If it gets timeout, we identify it as guilty and do hw reset. After that, we would do the normal resubmit step to resubmit left jobs.
2. Re-insert Bailing job to
mirror_list, and leave it to be handled by the main reset thread.3. For whole gpu reset(vram lost), do resubmit as the old way.
Signed-off-by Jack Zhang <[email protected]>---
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c| 72 ++++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c | 2 +- drivers/gpu/drm/scheduler/sched_main.c | 75 ++++++++++++++++++++++ include/drm/gpu_scheduler.h | 2 +4 files changed, 148 insertions(+), 3 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4639,6 +4639,7 @@ int amdgpu_device_gpu_recover(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-1int i, r = 0; bool need_emergency_restart = false; bool audio_suspended = false; +int tmp_vram_lost_counter; /** Special case: RAS triggered and full reset isn't supported @@ -4689,9 +4690,14 @@ int amdgpu_device_gpu_recover(struct
amdgpu_device*adev,Quoted 1 line
dev_info(adev->dev, "Bailing on TDR for s_job:%llx, as another
already in progress",
Quoted 11 lines
job ?
job->base.id: -1);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-2-/* even we skipped this reset, still need to set the job to guilty */ -if (job) +if (job) { +/* re-insert node to avoid memory leak */ +spin_lock (&job->base.sched->job_list_lock); +list_add (&job->base.node, &job->base.sched->pending_list); +spin_unlock (&job->base.sched->job_list_lock); +/* even we skipped this reset, still need to set the job to guilty +*/ Quoted 2 lines
drm_sched_increase_karma(&job->base);
+}I think this piece should be in a standalone patch as it comes to fix a bug of leaking jobs and not directly related to find actual guilty job. Also, this is not the only place where the problem arises - it also arises in other drivers where they check that guilty job's fence already signaled and bail out before reinsertion of bad job to mirror list. Seems to me better fix would be to handle this within scheduler code by adding specific return value to drm_sched_backend_ops.timedout_job marking that the code terminated early - before calling
drm_sched_stopand sodrm_sched_job_timedoutwould know this and then reinsert the job back tomirror_listitself.drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct
Quoted 4 lines
goto
skip_recovery;
}drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +0
-0@@ -4788,6 +4794,7 @@ int amdgpu_device_gpu_recover(struct
amdgpu_device*adev,drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1
-0} } +tmp_vram_lost_counter =atomic_read (&((adev)->vram_lost_counter)); /* Actual ASIC resets if needed.*/ /* TODO Implement XGMI hive reset logic for SRIOV */ if (amdgpu_sriov_vf(adev)) {@@ -4805,6 +4812,67 @@ int amdgpu_device_gpu_recover(struct
amdgpu_device*adev,Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +6
-0/* Post ASIC reset for all devs .*/ list_for_each_entry(tmp_adev, device_list_handle, gmc.xgmi.head) { +if (amdgpu_gpu_recovery ==2 && +!(tmp_vram_lost_counter <atomic_read (&adev->vram_lost_counter))) +{ + +for (i =0 ; i <AMDGPU_MAX_RINGS ; ++i) { +struct amdgpu_ring *ring = tmp_adev->rings[i];drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +10
-0+int ret =0 ; +struct drm_sched_job *s_job; + +if (!ring || !ring->sched.thread) +continue ; + +/* No point to resubmit jobs if we didn't HW reset*/ +if (!tmp_adev->asic_reset_res && !job_signaled) { + +s_job = list_first_entry_or_null(&ring->sched.pending_list, struct
drm_sched_job, list);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +4
-0+if (s_job ==NULL ) +continue ; + +/* clear job's guilty and depend the folowing step to decide the real one */
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +7
-0+drm_sched_reset_karma (s_job); +drm_sched_resubmit_jobs2 (&ring->sched,1 ); +ret =dma_fence_wait_timeout (s_job->s_fence->parent, false, +ring->sched.timeout); + +if (ret ==0 ) {/* timeout */ +DRM_ERROR("Found the real bad job! ring:%s, job_id:%llx\n",
ring->sched.name,s_job->id);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +11
-0+/* set guilty */ +drm_sched_increase_karma (s_job); + +/* do hw reset */ +if (amdgpu_sriov_vf (adev)) { +amdgpu_virt_fini_data_exchange (adev); +r =amdgpu_device_reset_sriov (adev, false); +if (r) +adev->asic_reset_res = r; +}else { +r = amdgpu_do_asic_reset(hive, device_list_handle,
&need_full_reset, false);drivers/gpu/drm/amd/amdgpu/amdgpu_device.c int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +5
-0+if (r && r == -EAGAIN ) +goto retry; +} + +/* add reset counter so that the following resubmitted job could flush vmid */
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c module_param_named(compute_multipipe,
Quoted 29 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +20
-0+atomic_inc (&tmp_adev->gpu_reset_counter); +continue ; +} + +/* got the hw fence, signal finished fence */ +atomic_dec (&ring->sched.num_jobs); +dma_fence_get (&s_job->s_fence->finished); +dma_fence_signal (&s_job->s_fence->finished); +dma_fence_put (&s_job->s_fence->finished); + + +/* remove node from list and free the job */ +spin_lock (&ring->sched.job_list_lock); +list_del_init (&s_job->node); +spin_unlock (&ring->sched.job_list_lock); +ring->sched.ops->free_job (s_job); +} +} +} + for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {struct
amdgpu_ring*ring = tmp_adev->rings[i];drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0@@ -509,7 +509,7 @@ module_param_named(compute_multipipe,
amdgpu_compute_multipipe, int, 0444);drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c module_param_named(compute_multipipe, · line 510
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +0
-0* DOC: gpu_recovery (int) * Set to enable GPU recovery mechanism (1 = enable, 0 = disable).The default is -1 (auto, disabled except SRIOV).
drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct
Quoted 14 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +2
-1*/ -MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (1 = enable, 0 = disable, -1 = auto)"); +MODULE_PARM_DESC(gpu_recovery, "Enable GPU recovery mechanism, (2 = +advanced tdr mode, 1 = enable, 0 = disable, -1 = auto)"); module_param_named(gpu_recovery, amdgpu_gpu_recovery, int, 0444);/**
drivers/gpu/drm/scheduler/sched_main.c +0
-0@@ -395,6 +395,81 @@ void drm_sched_increase_karma(struct
drm_sched_job*bad)Quoted 14 lines
drivers/gpu/drm/scheduler/sched_main.c +11
-0} EXPORT_SYMBOL(drm_sched_increase_karma); + +void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max) { +struct drm_sched_job *s_job, *tmp; +uint64_t guilty_context; +bool found_guilty = false; +struct dma_fence *fence; +int i =0 ; + +list_for_each_entry_safe(s_job, tmp, &sched->pending_list, list) { +struct drm_sched_fence *s_fence = s_job->s_fence;drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad)
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+ +if (i >= max) +break ; + +if (!found_guilty &&atomic_read (&s_job->karma) > sched->hang_limit) { +found_guilty = true; +guilty_context = s_job->s_fence->scheduled.context; +} + +if (found_guilty && s_job->s_fence->scheduled.context ==
guilty_context)Quoted 7 lines
drivers/gpu/drm/scheduler/sched_main.c +7
-0+dma_fence_set_error (&s_fence->finished, -ECANCELED ); + +dma_fence_put (s_job->s_fence->parent); +fence = sched->ops->run_job (s_job); +i++; + +if (IS_ERR_OR_NULL (fence)) {drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 435
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+if (IS_ERR (fence)) +dma_fence_set_error (&s_fence->finished,PTR_ERR (fence)); + +s_job->s_fence->parent =NULL ; +}else { +s_job->s_fence->parent = fence; +} +} +} +EXPORT_SYMBOL (drm_sched_resubmit_jobs2);This is identical to
drm_sched_resubmit_jobsin all but the 'int max' handling, can't you reusedrm_sched_resubmit_jobsby passing max argument==1 for the find guilty run and then, for the later normal run passing max==MAX_INT to avoid break the iteration to early ?drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad)
Quoted 11 lines
drivers/gpu/drm/scheduler/sched_main.c +11
-0+ + + +void drm_sched_reset_karma (struct drm_sched_job *bad) { +int i; +struct drm_sched_entity *tmp; +struct drm_sched_entity *entity; +struct drm_gpu_scheduler *sched = bad->sched; + +/* don't reset @bad's karma if it's from KERNEL RQ, +* because sometimes GPU hang would cause kernel jobs (like VM updating jobs)
Quoted 14 lines
drivers/gpu/drm/scheduler/sched_main.c +14
-0+* corrupt but keep in mind that kernel jobs always considered good. +*/ +if (bad->s_priority !=DRM_SCHED_PRIORITY_KERNEL ) { +atomic_set (&bad->karma,0 ); +for (i =DRM_SCHED_PRIORITY_MIN ; i <DRM_SCHED_PRIORITY_KERNEL ; + i++) { +struct drm_sched_rq *rq = &sched->sched_rq[i]; + +spin_lock (&rq->lock); +list_for_each_entry_safe(entity, tmp, &rq->entities, list) { +if (bad->s_fence->scheduled.context == +entity->fence_context) { +if (entity->guilty) +atomic_set (entity->guilty,0 );drivers/gpu/drm/scheduler/sched_main.c void drm_sched_increase_karma(struct drm_sched_job *bad) · line 471
Quoted 10 lines
drivers/gpu/drm/scheduler/sched_main.c +10
-0+break ; +} +} +spin_unlock (&rq->lock); +if (&entity->list != &rq->entities) +break ; +} +} +} +EXPORT_SYMBOL (drm_sched_reset_karma);Same as above, very similar
drm_sched_increase_karma, I would add a flag and just reuse code instead of duplucation.Andrey
include/drm/gpu_scheduler.h void drm_sched_wakeup(struct drm_gpu_scheduler
Quoted 9 lines
drivers/gpu/drm/scheduler/sched_main.c +1
-0+ /*** drm_sched_stop - stop the scheduler * include/drm/gpu_scheduler.h +0
-0@@ -321,7 +321,9 @@ void drm_sched_wakeup(struct drm_gpu_scheduler*sched);
Quoted 1 line
void drm_sched_stop(struct
drm_gpu_scheduler*sched, struct
drm_sched_job*bad);Quoted 1 line
void drm_sched_start(struct
drm_gpu_scheduler*sched, bool
full_recovery);
Quoted 9 lines
Quoted 9 lines
void
drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched);include/drm/gpu_scheduler.h +2
-0+void drm_sched_resubmit_jobs2 (struct drm_gpu_scheduler *sched,int +max);void
drm_sched_increase_karma(struct drm_sched_job *bad); +voiddrm_sched_reset_karma(struct drm_sched_job *bad); booldrm_sched_dependency_optimized(struct dma_fence* fence, struct drm_sched_entity *entity);
voiddrm_sched_fault(struct drm_gpu_scheduler *sched);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx