Skip to content

Commit 8285af8

Browse files
author
Philipp Stanner
committed
drm/sched/tests: Make timedout_job callback a better role model
Since the drm_mock_scheduler does not have real users in userspace, nor does it have real hardware or firmware rings, it's not necessary to signal timedout fences nor free jobs - from a functional standpoint. Still, the dma_fence framework establishes the hard rule that all fences must always get signaled. The unit tests, moreover, should as much as possible represent the intended usage of the scheduler API. Furthermore, this later enables simplifying the mock scheduler's teardown code path. Make sure timed out hardware fences get signaled with the appropriate error code. Signed-off-by: Philipp Stanner <[email protected]> Acked-by: Danilo Krummrich <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent bdad4aa commit 8285af8

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

drivers/gpu/drm/scheduler/tests/mock_scheduler.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,12 +200,36 @@ static struct dma_fence *mock_sched_run_job(struct drm_sched_job *sched_job)
200200
return &job->hw_fence;
201201
}
202202

203+
/*
204+
* Normally, drivers would take appropriate measures in this callback, such as
205+
* killing the entity the faulty job is associated with, resetting the hardware
206+
* and / or resubmitting non-faulty jobs.
207+
*
208+
* For the mock scheduler, there are no hardware rings to be resetted nor jobs
209+
* to be resubmitted. Thus, this function merely ensures that
210+
* a) timedout fences get signaled properly and removed from the pending list
211+
* b) the mock scheduler framework gets informed about the timeout via a flag
212+
* c) The drm_sched_job, not longer needed, gets freed
213+
*/
203214
static enum drm_gpu_sched_stat
204215
mock_sched_timedout_job(struct drm_sched_job *sched_job)
205216
{
217+
struct drm_mock_scheduler *sched = drm_sched_to_mock_sched(sched_job->sched);
206218
struct drm_mock_sched_job *job = drm_sched_job_to_mock_job(sched_job);
219+
unsigned long flags;
207220

208-
job->flags |= DRM_MOCK_SCHED_JOB_TIMEDOUT;
221+
spin_lock_irqsave(&sched->lock, flags);
222+
if (!dma_fence_is_signaled_locked(&job->hw_fence)) {
223+
list_del(&job->link);
224+
job->flags |= DRM_MOCK_SCHED_JOB_TIMEDOUT;
225+
dma_fence_set_error(&job->hw_fence, -ETIMEDOUT);
226+
dma_fence_signal_locked(&job->hw_fence);
227+
}
228+
spin_unlock_irqrestore(&sched->lock, flags);
229+
230+
dma_fence_put(&job->hw_fence);
231+
drm_sched_job_cleanup(sched_job);
232+
/* Mock job itself is freed by the kunit framework. */
209233

210234
return DRM_GPU_SCHED_STAT_NOMINAL;
211235
}

0 commit comments

Comments
 (0)