[PATCH] drm/sched: Add native dependency support to drm_sched

Boris Brezillon boris.brezillon at collabora.com
Mon Jun 12 13:05:53 UTC 2023


Hi Donald,

On Thu, 8 Jun 2023 13:23:26 +0000
Donald Robson <Donald.Robson at imgtec.com> wrote:

>  /**
>   * drm_sched_job_arm - arm a scheduler job for execution
>   * @job: scheduler job to arm
> @@ -669,6 +755,7 @@ void drm_sched_job_arm(struct drm_sched_job *job)
>  	job->s_priority = entity->rq - sched->sched_rq;
>  	job->id = atomic64_inc_return(&sched->job_id_count);
>  
> +	drm_sched_sort_native_deps(job);

If we get [1] accepted, we no longer need to sort the array. We can
just skip native dependencies as we iterate over the array in
drm_sched_job_dependency() with something like:

       f = xa_load(&job->dependencies, job->last_dependency);
       while (f) {
               struct drm_sched_fence *s_fence;
               struct dma_fence *scheduled_fence;

               job->last_dependency++;

               /* Not a native dependency, return the fence directly. */
               if (!job->sched->ops->dependency_is_native ||
                   !job->sched->ops->dependency_is_native(f))
                       return dma_fence_get(f);

               /*
                * If the native fence is a drm_sched_fence object, we
                * ensure the job has been submitted so drm_sched_fence
                * ::parent points to a valid dma_fence object.
                */
               s_fence = to_drm_sched_fence(f);
               scheduled_fence = s_fence ?
				 dma_fence_get_rcu(&s_fence->scheduled) :
                                 NULL;

               if (scheduled_fence)
                       return scheduled_fence;

               /* Otherwise we skip the native fence and check the next fence. */
               f = xa_load(&job->dependencies, job->last_dependency);
        }

And, in the driver, when you get to submit the job, you can gather
the native deps with a simple xa_for_each() loop:

	xa_for_each(&job->dependencies, index, f) {
		/* If the fence is not signaled, it must be a native fence,
		 * because drm_sched_entity waited for all non-native ones.
		 */
		if (!dma_fence_is_signaled(f))
			// DO SOMETHING
	}

>  	drm_sched_fence_init(job->s_fence, job->entity);
>  }

Regards,

Boris

[1]https://patchwork.freedesktop.org/patch/541956/


More information about the dri-devel mailing list