]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/sched/tests: Make timedout_job callback a better role model
authorPhilipp Stanner <phasta@kernel.org>
Thu, 5 Jun 2025 13:41:55 +0000 (15:41 +0200)
committerPhilipp Stanner <phasta@kernel.org>
Mon, 30 Jun 2025 15:37:51 +0000 (17:37 +0200)
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 <phasta@kernel.org>
Acked-by: Danilo Krummrich <dakr@kernel.org>
Link: https://lore.kernel.org/r/20250605134154.191764-2-phasta@kernel.org
drivers/gpu/drm/scheduler/tests/mock_scheduler.c

index 7f947ab9d32259d72186a6c0bff0b666fdee1821..49d067fecd67f705f7a7b957ce04699e3cc7af76 100644 (file)
@@ -200,12 +200,36 @@ static struct dma_fence *mock_sched_run_job(struct drm_sched_job *sched_job)
        return &job->hw_fence;
 }
 
+/*
+ * Normally, drivers would take appropriate measures in this callback, such as
+ * killing the entity the faulty job is associated with, resetting the hardware
+ * and / or resubmitting non-faulty jobs.
+ *
+ * For the mock scheduler, there are no hardware rings to be resetted nor jobs
+ * to be resubmitted. Thus, this function merely ensures that
+ *   a) timedout fences get signaled properly and removed from the pending list
+ *   b) the mock scheduler framework gets informed about the timeout via a flag
+ *   c) The drm_sched_job, not longer needed, gets freed
+ */
 static enum drm_gpu_sched_stat
 mock_sched_timedout_job(struct drm_sched_job *sched_job)
 {
+       struct drm_mock_scheduler *sched = drm_sched_to_mock_sched(sched_job->sched);
        struct drm_mock_sched_job *job = drm_sched_job_to_mock_job(sched_job);
+       unsigned long flags;
 
-       job->flags |= DRM_MOCK_SCHED_JOB_TIMEDOUT;
+       spin_lock_irqsave(&sched->lock, flags);
+       if (!dma_fence_is_signaled_locked(&job->hw_fence)) {
+               list_del(&job->link);
+               job->flags |= DRM_MOCK_SCHED_JOB_TIMEDOUT;
+               dma_fence_set_error(&job->hw_fence, -ETIMEDOUT);
+               dma_fence_signal_locked(&job->hw_fence);
+       }
+       spin_unlock_irqrestore(&sched->lock, flags);
+
+       dma_fence_put(&job->hw_fence);
+       drm_sched_job_cleanup(sched_job);
+       /* Mock job itself is freed by the kunit framework. */
 
        return DRM_GPU_SCHED_STAT_NOMINAL;
 }