Re: [PATCH] drm/panthor: Skip job dependencies when we can
From: Boris Brezillon
Date: Wed Dec 02 2026 - 05:09:39 EST
On Tue, 01 Dec 2026 15:09:47 +0100
Philipp Stanner <phasta@xxxxxxxxxxx> wrote:
> On Tue, 2026-12-01 at 14:58 +0100, Boris Brezillon wrote:
> > If a job is passed a dependency that's coming from the same queue the
> > job is targeting, we can get rid of the dependency because of the
> > implicit serialization provided by the queue.
>
> Shouldn't drm_sched be doing that already? See below.
It does do that if the dependency added to the XArray is not a
container fence. But the case we're having here is a fence_array
(sync_fd export) or fence_chain (timeline syncobj) being added directly
to the dependency list.
>
> Am I understanding correctly that someone sets a dependency for
> something on the same userspace context, not merely relying on FIFO
> behavior?
Most of the time userspace gets passed objects to wait on
(Vk[Timeline]Semaphore/Fence) without knowing where they come from, so
extracting info on whether this is the same queue or not is hard to
figure out at this level. The KMD has full knowledge of this, which
makes it the perfect place to do the NOP-dep eviction.
>
> JobQueue currently is not deadlock-resistant against that because I
> expected drivers to ignore such deps.
Yep, it's not so much that we're running into a deadlock. This patch
really is about optimizing stuff by letting drm_sched queue the job
before its predecessor on the same queue are done. By doing that, we
avoid an extra FW <-> CPU round-trip to signal the fence and wake up
drm_sched to re-evaluate the current entity dependency and finally
push the job to the ringbuf.
>
> >
> >
>
> […]
>
> >
> > +static bool can_skip_dep(const struct drm_sched_job *job, struct dma_fence *fence)
> > +{
> > + if (!fence)
> > + return true;
> > +
> > + /* This fence comes from our queue, and the serialization happening at
> > + * the queue level makes it so we can skip the CPU wait.
> > + */
> > + if (fence->context == job->entity->fence_context ||
> > + fence->context == job->entity->fence_context + 1)
> > + return true;
> > +
>
> […]
>
> > + if (can_skip_dep(job, fence)) {
> > + dma_fence_put(fence);
>
> drm_sched does:
>
> static bool drm_sched_entity_add_dependency_cb(struct drm_sched_entity *entity,
> struct drm_sched_job *sched_job)
> {
> struct drm_gpu_scheduler *sched = entity->rq->sched;
> 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
> */
> dma_fence_put(entity->dependency);
> return false;
> }
>
>
>
> I seem to be missing something, because at first glance drm_sched
> should ignore your added dependencies.
The catch here is that it doesn't work with container fences. So,
either we explode container fences at insertion time (when
drm_sched_job_add_dependency() & co is called), or we do it in
drm_sched_entity_add_dependency_cb() and try to see through the
container. The former potentially means adding more entries in the
Xarray, the latter implies reworking the entity dep tracking logic to
save the position inside the container being considered (so basically
an _unwrap() cursor stored somewhere). There's also the case where the
GPU <-> CPU round-trip doesn't matter because the HW pipeline
capabilities are too limited (if you have a queue of exactly one job,
you'll have to wait for the previous job to signal its fence before
pushing a new job anyway, so there's no point splitting container
fences if it doesn't save you this round-trip).
TL;DR yes drm_sched has this logic baked in, but it's highly dependent
on how the driver adds its dependencies, and panthor was just ignoring
this fact until now.