drm/amdgpu: fix preemption unit test
authorJack Xiao <Jack.Xiao@amd.com>
Fri, 10 Jul 2020 04:34:52 +0000 (12:34 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 10 Jul 2020 21:42:56 +0000 (17:42 -0400)
Remove signaled jobs from job list and ensure the
job was indeed preempted.

Signed-off-by: Jack Xiao <Jack.Xiao@amd.com>
Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c

index e16e58e..a3fa156 100644 (file)
@@ -1343,27 +1343,37 @@ static void amdgpu_ib_preempt_job_recovery(struct drm_gpu_scheduler *sched)
 static void amdgpu_ib_preempt_mark_partial_job(struct amdgpu_ring *ring)
 {
        struct amdgpu_job *job;
-       struct drm_sched_job *s_job;
+       struct drm_sched_job *s_job, *tmp;
        uint32_t preempt_seq;
        struct dma_fence *fence, **ptr;
        struct amdgpu_fence_driver *drv = &ring->fence_drv;
        struct drm_gpu_scheduler *sched = &ring->sched;
+       bool preempted = true;
 
        if (ring->funcs->type != AMDGPU_RING_TYPE_GFX)
                return;
 
        preempt_seq = le32_to_cpu(*(drv->cpu_addr + 2));
-       if (preempt_seq <= atomic_read(&drv->last_seq))
-               return;
+       if (preempt_seq <= atomic_read(&drv->last_seq)) {
+               preempted = false;
+               goto no_preempt;
+       }
 
        preempt_seq &= drv->num_fences_mask;
        ptr = &drv->fences[preempt_seq];
        fence = rcu_dereference_protected(*ptr, 1);
 
+no_preempt:
        spin_lock(&sched->job_list_lock);
-       list_for_each_entry(s_job, &sched->ring_mirror_list, node) {
+       list_for_each_entry_safe(s_job, tmp, &sched->ring_mirror_list, node) {
+               if (dma_fence_is_signaled(&s_job->s_fence->finished)) {
+                       /* remove job from ring_mirror_list */
+                       list_del_init(&s_job->node);
+                       sched->ops->free_job(s_job);
+                       continue;
+               }
                job = to_amdgpu_job(s_job);
-               if (job->fence == fence)
+               if (preempted && job->fence == fence)
                        /* mark the job as preempted */
                        job->preemption_status |= AMDGPU_IB_PREEMPTED;
        }