<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><br>
</p>
<div class="moz-cite-prefix">On 4/23/19 10:44 AM, Zhou, David(ChunMing) wrote:<br>
</div>
<blockquote type="cite" cite="mid:eqyp0q-xw3o4t-5si8qg-3jxnvt7nb0s5trrutj-uelqagfwr69wprwk7ty7v2u3s1j0tabcslq-uksg9o3oidy22540hd-kfbkbo-hbl55n-zeoeno-ygqeaw5tea3s-oa7egj-jmt1w8-n5xit0m1pyob.1556030645243@email.android.com">
This patch is to fix deadlock between fence->lock and sched->job_list_lock, right?<br>
So I suggest to just move list_del_init(&s_job->node) from drm_sched_process_job to work thread. That will avoid deadlock described in the link.
</blockquote>
<p><br>
</p>
<p>Do you mean restoring back scheduling work from HW fence interrupt handler and deleting there ? Yes, I suggested this as an option (take a look at my comment 9 in
<a class="moz-txt-link-freetext" href="https://bugs.freedesktop.org/show_bug.cgi?id=109692">
https://bugs.freedesktop.org/show_bug.cgi?id=109692</a>) but since we still have to wait for all fences in flight to signal to avoid the problem fixed in '3741540 drm/sched: Rework HW fence processing.' this thing becomes somewhat complicated and so Christian
came up with the core idea in this patch which is to do all deletions/insertions thread safe by grantee it's always dome from one thread. It does simplify the handling.</p>
<p>Andrey</p>
<p><br>
</p>
<blockquote type="cite" cite="mid:eqyp0q-xw3o4t-5si8qg-3jxnvt7nb0s5trrutj-uelqagfwr69wprwk7ty7v2u3s1j0tabcslq-uksg9o3oidy22540hd-kfbkbo-hbl55n-zeoeno-ygqeaw5tea3s-oa7egj-jmt1w8-n5xit0m1pyob.1556030645243@email.android.com">
<div style="line-height:1.5"><br>
<br>
-------- Original Message --------<br>
Subject: Re: [PATCH v5 3/6] drm/scheduler: rework job destruction<br>
From: "Grodzovsky, Andrey" <andrey.grodzovsky@amd.com><br>
To: "Zhou, David(ChunMing)" <david1.zhou@amd.com>,<a class="moz-txt-link-abbreviated" href="mailto:dri-devel@lists.freedesktop.org,amd-gfx@lists.freedesktop.org,eric@anholt.net,etnaviv@lists.freedesktop.org,ckoenig.leichtzumerken@gmail.com">dri-devel@lists.freedesktop.org,amd-gfx@lists.freedesktop.org,eric@anholt.net,etnaviv@lists.freedesktop.org,ckoenig.leichtzumerken@gmail.com</a><br>
CC: "Kazlauskas, Nicholas" <nicholas.kazlauskas@amd.com>,"Koenig, Christian" <christian.koenig@amd.com>
<br>
<br>
<blockquote style="margin:0 0 0 0.8ex;border-left:1px
#ccc solid;padding-left:1ex">
<blockquote class="quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
On 4/22/19 8:48 AM, Chunming Zhou wrote:<br>
> Hi Andrey,<br>
><br>
> static void drm_sched_process_job(struct dma_fence *f, struct<br>
> dma_fence_cb *cb)<br>
> {<br>
> ...<br>
> spin_lock_irqsave(&sched->job_list_lock, flags);<br>
> /* remove job from ring_mirror_list */<br>
> list_del_init(&s_job->node);<br>
> spin_unlock_irqrestore(&sched->job_list_lock, flags);<br>
> [David] How about just remove above to worker from irq process? Any<br>
> problem? Maybe I missed previous your discussion, but I think removing<br>
> lock for list is a risk for future maintenance although you make sure<br>
> thread safe currently.<br>
><br>
> -David<br>
<br>
<br>
We remove the lock exactly because of the fact that insertion and <br>
removal to/from the list will be done form exactly one thread at ant <br>
time now. So I am not sure I understand what you mean.<br>
<br>
Andrey<br>
<br>
<br>
><br>
> ...<br>
><br>
> schedule_work(&s_job->finish_work);<br>
> }<br>
><br>
> 在 2019/4/18 23:00, Andrey Grodzovsky 写道:<br>
>> From: Christian König <a class="moz-txt-link-rfc2396E" href="mailto:christian.koenig@amd.com">
<christian.koenig@amd.com></a><br>
>><br>
>> We now destroy finished jobs from the worker thread to make sure that<br>
>> we never destroy a job currently in timeout processing.<br>
>> By this we avoid holding lock around ring mirror list in drm_sched_stop<br>
>> which should solve a deadlock reported by a user.<br>
>><br>
>> v2: Remove unused variable.<br>
>> v4: Move guilty job free into sched code.<br>
>> v5:<br>
>> Move sched->hw_rq_count to drm_sched_start to account for counter<br>
>> decrement in drm_sched_stop even when we don't call resubmit jobs<br>
>> if guily job did signal.<br>
>><br>
>> Bugzilla: <a class="moz-txt-link-freetext" href="https://bugs.freedesktop.org/show_bug.cgi?id=109692">
https://bugs.freedesktop.org/show_bug.cgi?id=109692</a><br>
>><br>
>> Signed-off-by: Christian König <a class="moz-txt-link-rfc2396E" href="mailto:christian.koenig@amd.com">
<christian.koenig@amd.com></a><br>
>> Signed-off-by: Andrey Grodzovsky <a class="moz-txt-link-rfc2396E" href="mailto:andrey.grodzovsky@amd.com">
<andrey.grodzovsky@amd.com></a><br>
>> ---<br>
>> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 9 +-<br>
>> drivers/gpu/drm/etnaviv/etnaviv_dump.c | 4 -<br>
>> drivers/gpu/drm/etnaviv/etnaviv_sched.c | 2 +-<br>
>> drivers/gpu/drm/lima/lima_sched.c | 2 +-<br>
>> drivers/gpu/drm/panfrost/panfrost_job.c | 2 +-<br>
>> drivers/gpu/drm/scheduler/sched_main.c | 159 +++++++++++++++++------------<br>
>> drivers/gpu/drm/v3d/v3d_sched.c | 2 +-<br>
>> include/drm/gpu_scheduler.h | 6 +-<br>
>> 8 files changed, 102 insertions(+), 84 deletions(-)<br>
>><br>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
>> index 7cee269..a0e165c 100644<br>
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
>> @@ -3334,7 +3334,7 @@ static int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,<br>
>> if (!ring || !ring->sched.thread)<br>
>> continue;<br>
>> <br>
>> - drm_sched_stop(&ring->sched);<br>
>> + drm_sched_stop(&ring->sched, &job->base);<br>
>> <br>
>> /* after all hw jobs are reset, hw fence is meaningless, so force_completion */<br>
>> amdgpu_fence_driver_force_completion(ring);<br>
>> @@ -3343,8 +3343,6 @@ static int amdgpu_device_pre_asic_reset(struct amdgpu_device *adev,<br>
>> if(job)<br>
>> drm_sched_increase_karma(&job->base);<br>
>> <br>
>> -<br>
>> -<br>
>> if (!amdgpu_sriov_vf(adev)) {<br>
>> <br>
>> if (!need_full_reset)<br>
>> @@ -3482,8 +3480,7 @@ static int amdgpu_do_asic_reset(struct amdgpu_hive_info *hive,<br>
>> return r;<br>
>> }<br>
>> <br>
>> -static void amdgpu_device_post_asic_reset(struct amdgpu_device *adev,<br>
>> - struct amdgpu_job *job)<br>
>> +static void amdgpu_device_post_asic_reset(struct amdgpu_device *adev)<br>
>> {<br>
>> int i;<br>
>> <br>
>> @@ -3623,7 +3620,7 @@ int amdgpu_device_gpu_recover(struct amdgpu_device *adev,<br>
>> <br>
>> /* Post ASIC reset for all devs .*/<br>
>> list_for_each_entry(tmp_adev, device_list_handle, gmc.xgmi.head) {<br>
>> - amdgpu_device_post_asic_reset(tmp_adev, tmp_adev == adev ? job : NULL);<br>
>> + amdgpu_device_post_asic_reset(tmp_adev);<br>
>> <br>
>> if (r) {<br>
>> /* bad news, how to tell it to userspace ? */<br>
>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_dump.c b/drivers/gpu/drm/etnaviv/etnaviv_dump.c<br>
>> index 33854c9..5778d9c 100644<br>
>> --- a/drivers/gpu/drm/etnaviv/etnaviv_dump.c<br>
>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_dump.c<br>
>> @@ -135,13 +135,11 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu)<br>
>> mmu_size + gpu->buffer.size;<br>
>> <br>
>> /* Add in the active command buffers */<br>
>> - spin_lock_irqsave(&gpu->sched.job_list_lock, flags);<br>
>> list_for_each_entry(s_job, &gpu->sched.ring_mirror_list, node) {<br>
>> submit = to_etnaviv_submit(s_job);<br>
>> file_size += submit->cmdbuf.size;<br>
>> n_obj++;<br>
>> }<br>
>> - spin_unlock_irqrestore(&gpu->sched.job_list_lock, flags);<br>
>> <br>
>> /* Add in the active buffer objects */<br>
>> list_for_each_entry(vram, &gpu->mmu->mappings, mmu_node) {<br>
>> @@ -183,14 +181,12 @@ void etnaviv_core_dump(struct etnaviv_gpu *gpu)<br>
>> gpu->buffer.size,<br>
>> etnaviv_cmdbuf_get_va(&gpu->buffer));<br>
>> <br>
>> - spin_lock_irqsave(&gpu->sched.job_list_lock, flags);<br>
>> list_for_each_entry(s_job, &gpu->sched.ring_mirror_list, node) {<br>
>> submit = to_etnaviv_submit(s_job);<br>
>> etnaviv_core_dump_mem(&iter, ETDUMP_BUF_CMD,<br>
>> submit->cmdbuf.vaddr, submit->cmdbuf.size,<br>
>> etnaviv_cmdbuf_get_va(&submit->cmdbuf));<br>
>> }<br>
>> - spin_unlock_irqrestore(&gpu->sched.job_list_lock, flags);<br>
>> <br>
>> /* Reserve space for the bomap */<br>
>> if (n_bomap_pages) {<br>
>> diff --git a/drivers/gpu/drm/etnaviv/etnaviv_sched.c b/drivers/gpu/drm/etnaviv/etnaviv_sched.c<br>
>> index 6d24fea..a813c82 100644<br>
>> --- a/drivers/gpu/drm/etnaviv/etnaviv_sched.c<br>
>> +++ b/drivers/gpu/drm/etnaviv/etnaviv_sched.c<br>
>> @@ -109,7 +109,7 @@ static void etnaviv_sched_timedout_job(struct drm_sched_job *sched_job)<br>
>> }<br>
>> <br>
>> /* block scheduler */<br>
>> - drm_sched_stop(&gpu->sched);<br>
>> + drm_sched_stop(&gpu->sched, sched_job);<br>
>> <br>
>> if(sched_job)<br>
>> drm_sched_increase_karma(sched_job);<br>
>> diff --git a/drivers/gpu/drm/lima/lima_sched.c b/drivers/gpu/drm/lima/lima_sched.c<br>
>> index 97bd9c1..df98931 100644<br>
>> --- a/drivers/gpu/drm/lima/lima_sched.c<br>
>> +++ b/drivers/gpu/drm/lima/lima_sched.c<br>
>> @@ -300,7 +300,7 @@ static struct dma_fence *lima_sched_run_job(struct drm_sched_job *job)<br>
>> static void lima_sched_handle_error_task(struct lima_sched_pipe *pipe,<br>
>> struct lima_sched_task *task)<br>
>> {<br>
>> - drm_sched_stop(&pipe->base);<br>
>> + drm_sched_stop(&pipe->base, &task->base);<br>
>> <br>
>> if (task)<br>
>> drm_sched_increase_karma(&task->base);<br>
>> diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c b/drivers/gpu/drm/panfrost/panfrost_job.c<br>
>> index 0a7ed04..c6336b7 100644<br>
>> --- a/drivers/gpu/drm/panfrost/panfrost_job.c<br>
>> +++ b/drivers/gpu/drm/panfrost/panfrost_job.c<br>
>> @@ -385,7 +385,7 @@ static void panfrost_job_timedout(struct drm_sched_job *sched_job)<br>
>> sched_job);<br>
>> <br>
>> for (i = 0; i < NUM_JOB_SLOTS; i++)<br>
>> - drm_sched_stop(&pfdev->js->queue[i].sched);<br>
>> + drm_sched_stop(&pfdev->js->queue[i].sched, sched_job);<br>
>> <br>
>> if (sched_job)<br>
>> drm_sched_increase_karma(sched_job);<br>
>> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c<br>
>> index 19fc601..7816de7 100644<br>
>> --- a/drivers/gpu/drm/scheduler/sched_main.c<br>
>> +++ b/drivers/gpu/drm/scheduler/sched_main.c<br>
>> @@ -265,32 +265,6 @@ void drm_sched_resume_timeout(struct drm_gpu_scheduler *sched,<br>
>> }<br>
>> EXPORT_SYMBOL(drm_sched_resume_timeout);<br>
>> <br>
>> -/* job_finish is called after hw fence signaled<br>
>> - */<br>
>> -static void drm_sched_job_finish(struct work_struct *work)<br>
>> -{<br>
>> - struct drm_sched_job *s_job = container_of(work, struct drm_sched_job,<br>
>> - finish_work);<br>
>> - struct drm_gpu_scheduler *sched = s_job->sched;<br>
>> - unsigned long flags;<br>
>> -<br>
>> - /*<br>
>> - * Canceling the timeout without removing our job from the ring mirror<br>
>> - * list is safe, as we will only end up in this worker if our jobs<br>
>> - * finished fence has been signaled. So even if some another worker<br>
>> - * manages to find this job as the next job in the list, the fence<br>
>> - * signaled check below will prevent the timeout to be restarted.<br>
>> - */<br>
>> - cancel_delayed_work_sync(&sched->work_tdr);<br>
>> -<br>
>> - spin_lock_irqsave(&sched->job_list_lock, flags);<br>
>> - /* queue TDR for next job */<br>
>> - drm_sched_start_timeout(sched);<br>
>> - spin_unlock_irqrestore(&sched->job_list_lock, flags);<br>
>> -<br>
>> - sched->ops->free_job(s_job);<br>
>> -}<br>
>> -<br>
>> static void drm_sched_job_begin(struct drm_sched_job *s_job)<br>
>> {<br>
>> struct drm_gpu_scheduler *sched = s_job->sched;<br>
>> @@ -315,6 +289,13 @@ static void drm_sched_job_timedout(struct work_struct *work)<br>
>> if (job)<br>
>> job->sched->ops->timedout_job(job);<br>
>> <br>
>> + /*<br>
>> + * Guilty job did complete and hence needs to be manually removed<br>
>> + * See drm_sched_stop doc.<br>
>> + */<br>
>> + if (list_empty(&job->node))<br>
>> + job->sched->ops->free_job(job);<br>
>> +<br>
>> spin_lock_irqsave(&sched->job_list_lock, flags);<br>
>> drm_sched_start_timeout(sched);<br>
>> spin_unlock_irqrestore(&sched->job_list_lock, flags);<br>
>> @@ -371,23 +352,26 @@ EXPORT_SYMBOL(drm_sched_increase_karma);<br>
>> * @sched: scheduler instance<br>
>> * @bad: bad scheduler job<br>
>> *<br>
>> + * Stop the scheduler and also removes and frees all completed jobs.<br>
>> + * Note: bad job will not be freed as it might be used later and so it's<br>
>> + * callers responsibility to release it manually if it's not part of the<br>
>> + * mirror list any more.<br>
>> + *<br>
>> */<br>
>> -void drm_sched_stop(struct drm_gpu_scheduler *sched)<br>
>> +void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad)<br>
>> {<br>
>> - struct drm_sched_job *s_job;<br>
>> + struct drm_sched_job *s_job, *tmp;<br>
>> unsigned long flags;<br>
>> - struct dma_fence *last_fence = NULL;<br>
>> <br>
>> kthread_park(sched->thread);<br>
>> <br>
>> /*<br>
>> - * Verify all the signaled jobs in mirror list are removed from the ring<br>
>> - * by waiting for the latest job to enter the list. This should insure that<br>
>> - * also all the previous jobs that were in flight also already singaled<br>
>> - * and removed from the list.<br>
>> + * Iterate the job list from later to earlier one and either deactive<br>
>> + * their HW callbacks or remove them from mirror list if they already<br>
>> + * signaled.<br>
>> + * This iteration is thread safe as sched thread is stopped.<br>
>> */<br>
>> - spin_lock_irqsave(&sched->job_list_lock, flags);<br>
>> - list_for_each_entry_reverse(s_job, &sched->ring_mirror_list, node) {<br>
>> + list_for_each_entry_safe_reverse(s_job, tmp, &sched->ring_mirror_list, node) {<br>
>> if (s_job->s_fence->parent &&<br>
>> dma_fence_remove_callback(s_job->s_fence->parent,<br>
>> &s_job->cb)) {<br>
>> @@ -395,16 +379,30 @@ void drm_sched_stop(struct drm_gpu_scheduler *sched)<br>
>> s_job->s_fence->parent = NULL;<br>
>> atomic_dec(&sched->hw_rq_count);<br>
>> } else {<br>
>> - last_fence = dma_fence_get(&s_job->s_fence->finished);<br>
>> - break;<br>
>> + /*<br>
>> + * remove job from ring_mirror_list.<br>
>> + * Locking here is for concurrent resume timeout<br>
>> + */<br>
>> + spin_lock_irqsave(&sched->job_list_lock, flags);<br>
>> + list_del_init(&s_job->node);<br>
>> + spin_unlock_irqrestore(&sched->job_list_lock, flags);<br>
>> +<br>
>> + /*<br>
>> + * Wait for job's HW fence callback to finish using s_job<br>
>> + * before releasing it.<br>
>> + *<br>
>> + * Job is still alive so fence refcount at least 1<br>
>> + */<br>
>> + dma_fence_wait(&s_job->s_fence->finished, false);<br>
>> +<br>
>> + /*<br>
>> + * We must keep bad job alive for later use during<br>
>> + * recovery by some of the drivers<br>
>> + */<br>
>> + if (bad != s_job)<br>
>> + sched->ops->free_job(s_job);<br>
>> }<br>
>> }<br>
>> - spin_unlock_irqrestore(&sched->job_list_lock, flags);<br>
>> -<br>
>> - if (last_fence) {<br>
>> - dma_fence_wait(last_fence, false);<br>
>> - dma_fence_put(last_fence);<br>
>> - }<br>
>> }<br>
>> <br>
>> EXPORT_SYMBOL(drm_sched_stop);<br>
>> @@ -418,21 +416,22 @@ EXPORT_SYMBOL(drm_sched_stop);<br>
>> void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)<br>
>> {<br>
>> struct drm_sched_job *s_job, *tmp;<br>
>> + unsigned long flags;<br>
>> int r;<br>
>> <br>
>> - if (!full_recovery)<br>
>> - goto unpark;<br>
>> -<br>
>> /*<br>
>> * Locking the list is not required here as the sched thread is parked<br>
>> - * so no new jobs are being pushed in to HW and in drm_sched_stop we<br>
>> - * flushed all the jobs who were still in mirror list but who already<br>
>> - * signaled and removed them self from the list. Also concurrent<br>
>> + * so no new jobs are being inserted or removed. Also concurrent<br>
>> * GPU recovers can't run in parallel.<br>
>> */<br>
>> list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {<br>
>> struct dma_fence *fence = s_job->s_fence->parent;<br>
>> <br>
>> + atomic_inc(&sched->hw_rq_count);<br>
>> +<br>
>> + if (!full_recovery)<br>
>> + continue;<br>
>> +<br>
>> if (fence) {<br>
>> r = dma_fence_add_callback(fence, &s_job->cb,<br>
>> drm_sched_process_job);<br>
>> @@ -445,9 +444,12 @@ void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery)<br>
>> drm_sched_process_job(NULL, &s_job->cb);<br>
>> }<br>
>> <br>
>> - drm_sched_start_timeout(sched);<br>
>> + if (full_recovery) {<br>
>> + spin_lock_irqsave(&sched->job_list_lock, flags);<br>
>> + drm_sched_start_timeout(sched);<br>
>> + spin_unlock_irqrestore(&sched->job_list_lock, flags);<br>
>> + }<br>
>> <br>
>> -unpark:<br>
>> kthread_unpark(sched->thread);<br>
>> }<br>
>> EXPORT_SYMBOL(drm_sched_start);<br>
>> @@ -464,7 +466,6 @@ void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched)<br>
>> uint64_t guilty_context;<br>
>> bool found_guilty = false;<br>
>> <br>
>> - /*TODO DO we need spinlock here ? */<br>
>> list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {<br>
>> struct drm_sched_fence *s_fence = s_job->s_fence;<br>
>> <br>
>> @@ -477,7 +478,6 @@ void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched)<br>
>> dma_fence_set_error(&s_fence->finished, -ECANCELED);<br>
>> <br>
>> s_job->s_fence->parent = sched->ops->run_job(s_job);<br>
>> - atomic_inc(&sched->hw_rq_count);<br>
>> }<br>
>> }<br>
>> EXPORT_SYMBOL(drm_sched_resubmit_jobs);<br>
>> @@ -514,7 +514,6 @@ int drm_sched_job_init(struct drm_sched_job *job,<br>
>> return -ENOMEM;<br>
>> job->id = atomic64_inc_return(&sched->job_id_count);<br>
>> <br>
>> - INIT_WORK(&job->finish_work, drm_sched_job_finish);<br>
>> INIT_LIST_HEAD(&job->node);<br>
>> <br>
>> return 0;<br>
>> @@ -597,24 +596,53 @@ static void drm_sched_process_job(struct dma_fence *f, struct dma_fence_cb *cb)<br>
>> struct drm_sched_job *s_job = container_of(cb, struct drm_sched_job, cb);<br>
>> struct drm_sched_fence *s_fence = s_job->s_fence;<br>
>> struct drm_gpu_scheduler *sched = s_fence->sched;<br>
>> - unsigned long flags;<br>
>> -<br>
>> - cancel_delayed_work(&sched->work_tdr);<br>
>> <br>
>> atomic_dec(&sched->hw_rq_count);<br>
>> atomic_dec(&sched->num_jobs);<br>
>> <br>
>> - spin_lock_irqsave(&sched->job_list_lock, flags);<br>
>> - /* remove job from ring_mirror_list */<br>
>> - list_del_init(&s_job->node);<br>
>> - spin_unlock_irqrestore(&sched->job_list_lock, flags);<br>
>> + trace_drm_sched_process_job(s_fence);<br>
>> <br>
>> drm_sched_fence_finished(s_fence);<br>
>> -<br>
>> - trace_drm_sched_process_job(s_fence);<br>
>> wake_up_interruptible(&sched->wake_up_worker);<br>
>> +}<br>
>> +<br>
>> +/**<br>
>> + * drm_sched_cleanup_jobs - destroy finished jobs<br>
>> + *<br>
>> + * @sched: scheduler instance<br>
>> + *<br>
>> + * Remove all finished jobs from the mirror list and destroy them.<br>
>> + */<br>
>> +static void drm_sched_cleanup_jobs(struct drm_gpu_scheduler *sched)<br>
>> +{<br>
>> + unsigned long flags;<br>
>> +<br>
>> + /* Don't destroy jobs while the timeout worker is running */<br>
>> + if (!cancel_delayed_work(&sched->work_tdr))<br>
>> + return;<br>
>> +<br>
>> +<br>
>> + while (!list_empty(&sched->ring_mirror_list)) {<br>
>> + struct drm_sched_job *job;<br>
>> +<br>
>> + job = list_first_entry(&sched->ring_mirror_list,<br>
>> + struct drm_sched_job, node);<br>
>> + if (!dma_fence_is_signaled(&job->s_fence->finished))<br>
>> + break;<br>
>> +<br>
>> + spin_lock_irqsave(&sched->job_list_lock, flags);<br>
>> + /* remove job from ring_mirror_list */<br>
>> + list_del_init(&job->node);<br>
>> + spin_unlock_irqrestore(&sched->job_list_lock, flags);<br>
>> +<br>
>> + sched->ops->free_job(job);<br>
>> + }<br>
>> +<br>
>> + /* queue timeout for next job */<br>
>> + spin_lock_irqsave(&sched->job_list_lock, flags);<br>
>> + drm_sched_start_timeout(sched);<br>
>> + spin_unlock_irqrestore(&sched->job_list_lock, flags);<br>
>> <br>
>> - schedule_work(&s_job->finish_work);<br>
>> }<br>
>> <br>
>> /**<br>
>> @@ -656,9 +684,10 @@ static int drm_sched_main(void *param)<br>
>> struct dma_fence *fence;<br>
>> <br>
>> wait_event_interruptible(sched->wake_up_worker,<br>
>> + (drm_sched_cleanup_jobs(sched),<br>
>> (!drm_sched_blocked(sched) &&<br>
>> (entity = drm_sched_select_entity(sched))) ||<br>
>> - kthread_should_stop());<br>
>> + kthread_should_stop()));<br>
>> <br>
>> if (!entity)<br>
>> continue;<br>
>> diff --git a/drivers/gpu/drm/v3d/v3d_sched.c b/drivers/gpu/drm/v3d/v3d_sched.c<br>
>> index e740f3b..1a4abe7 100644<br>
>> --- a/drivers/gpu/drm/v3d/v3d_sched.c<br>
>> +++ b/drivers/gpu/drm/v3d/v3d_sched.c<br>
>> @@ -232,7 +232,7 @@ v3d_gpu_reset_for_timeout(struct v3d_dev *v3d, struct drm_sched_job *sched_job)<br>
>> <br>
>> /* block scheduler */<br>
>> for (q = 0; q < V3D_MAX_QUEUES; q++)<br>
>> - drm_sched_stop(&v3d->queue[q].sched);<br>
>> + drm_sched_stop(&v3d->queue[q].sched, sched_job);<br>
>> <br>
>> if (sched_job)<br>
>> drm_sched_increase_karma(sched_job);<br>
>> diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h<br>
>> index 0daca4d..9ee0f27 100644<br>
>> --- a/include/drm/gpu_scheduler.h<br>
>> +++ b/include/drm/gpu_scheduler.h<br>
>> @@ -167,9 +167,6 @@ struct drm_sched_fence *to_drm_sched_fence(struct dma_fence *f);<br>
>> * @sched: the scheduler instance on which this job is scheduled.<br>
>> * @s_fence: contains the fences for the scheduling of job.<br>
>> * @finish_cb: the callback for the finished fence.<br>
>> - * @finish_work: schedules the function @drm_sched_job_finish once the job has<br>
>> - * finished to remove the job from the<br>
>> - * @drm_gpu_scheduler.ring_mirror_list.<br>
>> * @node: used to append this struct to the @drm_gpu_scheduler.ring_mirror_list.<br>
>> * @id: a unique id assigned to each job scheduled on the scheduler.<br>
>> * @karma: increment on every hang caused by this job. If this exceeds the hang<br>
>> @@ -188,7 +185,6 @@ struct drm_sched_job {<br>
>> struct drm_gpu_scheduler *sched;<br>
>> struct drm_sched_fence *s_fence;<br>
>> struct dma_fence_cb finish_cb;<br>
>> - struct work_struct finish_work;<br>
>> struct list_head node;<br>
>> uint64_t id;<br>
>> atomic_t karma;<br>
>> @@ -296,7 +292,7 @@ int drm_sched_job_init(struct drm_sched_job *job,<br>
>> void *owner);<br>
>> void drm_sched_job_cleanup(struct drm_sched_job *job);<br>
>> void drm_sched_wakeup(struct drm_gpu_scheduler *sched);<br>
>> -void drm_sched_stop(struct drm_gpu_scheduler *sched);<br>
>> +void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad);<br>
>> void drm_sched_start(struct drm_gpu_scheduler *sched, bool full_recovery);<br>
>> void drm_sched_resubmit_jobs(struct drm_gpu_scheduler *sched);<br>
>> void drm_sched_increase_karma(struct drm_sched_job *bad);<br>
> _______________________________________________<br>
> amd-gfx mailing list<br>
> <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">
amd-gfx@lists.freedesktop.org</a><br>
> <a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">
https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a><br>
_______________________________________________<br>
amd-gfx mailing list<br>
<a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a><br>
<a class="moz-txt-link-freetext" href="https://lists.freedesktop.org/mailman/listinfo/amd-gfx">https://lists.freedesktop.org/mailman/listinfo/amd-gfx</a></blockquote>
</blockquote>
</christian.koenig@amd.com></nicholas.kazlauskas@amd.com></david1.zhou@amd.com></andrey.grodzovsky@amd.com></div>
</blockquote>
</body>
</html>