Re: [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time

From: Boris Brezillon

Date: Wed Dec 02 2026 - 04:29:04 EST


On Wed, 2 Dec 2026 09:11:02 +0000
Tvrtko Ursulin <tursulin@xxxxxxxxxxx> wrote:

> On 02/12/2026 09:00, Boris Brezillon wrote:
> > All dependencies get added through drm_sched_job_add_dependency() or
> > variants that call drm_sched_job_add_dependency() internally. At this
> > point, the job is already attached an entity, and we can do the
> > same-entity check there, so we don't insert the fence in the XArray in
> > the first place.
> >
> > Note that we keep the elimination logic in
> > drm_sched_entity_add_dependency_cb() too, because dependencies returned
> > by ::prepare_job() could also potentially be coming from the same
> > entity.
> >
> > Signed-off-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>
> > ---
> > drivers/gpu/drm/scheduler/sched_entity.c | 8 +-------
> > drivers/gpu/drm/scheduler/sched_main.c | 5 +++++
> > include/drm/gpu_scheduler.h | 20 ++++++++++++++++++++
> > 3 files changed, 26 insertions(+), 7 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/scheduler/sched_entity.c b/drivers/gpu/drm/scheduler/sched_entity.c
> > index 03e68b4102d5..39419b3ac552 100644
> > --- a/drivers/gpu/drm/scheduler/sched_entity.c
> > +++ b/drivers/gpu/drm/scheduler/sched_entity.c
> > @@ -473,13 +473,7 @@ static bool drm_sched_entity_add_dependency_cb(struct drm_sched_entity *entity,
> > struct dma_fence *fence = entity->dependency;
> > struct drm_sched_fence *s_fence;
> >
> > - if (fence->context == entity->fence_context ||
> > - fence->context == entity->fence_context + 1) {
> > - /*
> > - * Fence is a scheduled/finished fence from a job
> > - * which belongs to the same entity, we can ignore
> > - * fences from ourself
> > - */
> > + if (drm_sched_entity_can_skip_dependency(entity, fence)) {
> > dma_fence_put(entity->dependency);
> > return false;
> > }
> > diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> > index 85a49e219837..5f123a5e39ff 100644
> > --- a/drivers/gpu/drm/scheduler/sched_main.c
> > +++ b/drivers/gpu/drm/scheduler/sched_main.c
> > @@ -678,6 +678,11 @@ int drm_sched_job_add_dependency(struct drm_sched_job *job,
> > if (!fence)
> > return 0;
> >
> > + if (drm_sched_entity_can_skip_dependency(job->entity, fence)) {
> > + dma_fence_put(fence);
> > + return 0;
>
> I thought we could be braver and unwrap, snipping at the root much more
> than just the plain fences. As written it is not super exciting, but I
> am also not saying the two have to come together. It can be considered
> as a follow up.

Yeah, I've considered putting that in a dma_fence_unwrap_for_each()
loop, but then I realized some drivers might actually want to limit the
number of deps by keeping containers in place if they know there's no
HW pipelining to benefit from. Didn't you say you considered replacing
the xarray thing by a fence_array gathering all deps in just one mega
fence object? I assumed the use case was exactly that: only have one cb
registration at the drm_sched level. I can change that if you think all
drivers want this container extraction. Alternatively, we could make it
a drm_sched_entity option.

>
> > + }
> > +
> > /* Deduplicate if we already depend on a fence from the same context.
> > * This lets the size of the array of deps scale with the number of
> > * engines involved, rather than the number of BOs.
> > diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
> > index 3b0978fa8cf0..b2e9f6df68e6 100644
> > --- a/include/drm/gpu_scheduler.h
> > +++ b/include/drm/gpu_scheduler.h
> > @@ -734,6 +734,26 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
> > struct drm_gpu_scheduler **sched_list,
> > unsigned int num_sched_list);
> >
> > +/**
> > + * drm_sched_entity_can_skip_dependency() - Check if a dependency can be skipped.
> > + * @entity: entity the dependency will be waited on
> > + * @fence: fence representing the dependency
> > + *
> > + * Returns true if the dependency can be skipped, false if it can't.
> > + */
> > +static inline bool
> > +drm_sched_entity_can_skip_dependency(struct drm_sched_entity *entity,
> > + struct dma_fence *fence)
> > +{
> > + /*
> > + * Fence is a scheduled/finished fence from a job
> > + * which belongs to the same entity, we can ignore
> > + * fences from ourself
> > + */
> > + return fence->context == entity->fence_context ||
> > + fence->context == entity->fence_context + 1;
> > +}
>
> I'd put this into sched_internal.h unless we know someone really wants
> to use it and has a good enough reason.

Nope, no particular external user in mind for this helper, I just
forgot we had sched_internal.h for those.