All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boris Brezillon <boris.brezillon@collabora.com>
To: Philipp Stanner <phasta@mailbox.org>
Cc: phasta@kernel.org, "Steven Price" <steven.price@arm.com>,
	"Liviu Dudau" <liviu.dudau@arm.com>,
	"Akash Goel" <akash.goel@arm.com>,
	"Karunika Choo" <karunika.choo@arm.com>,
	"Lukas Zapolskas" <lukas.zapolskas@arm.com>,
	"Chris Diamand" <chris.diamand@arm.com>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Sumit Semwal" <sumit.semwal@linaro.org>,
	"Christian König" <christian.koenig@amd.com>,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org,
	"Xianzhong Li" <xianzhong.li@nxp.com>
Subject: Re: [PATCH] drm/panthor: Skip job dependencies when we can
Date: Wed, 2 Dec 2026 11:09:14 +0100	[thread overview]
Message-ID: <20261202110914.24479237@fedora1.home> (raw)
In-Reply-To: <e53389813348fb03d55eb0e4f9a5826f3b4c6981.camel@mailbox.org>

On Tue, 01 Dec 2026 15:09:47 +0100
Philipp Stanner <phasta@mailbox.org> 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.

  reply	other threads:[~2026-12-02 10:09 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 13:58 [PATCH] drm/panthor: Skip job dependencies when we can Boris Brezillon
2026-12-01 14:09 ` Philipp Stanner
2026-12-02 10:09   ` Boris Brezillon [this message]
2026-12-01 14:11 ` Tvrtko Ursulin
2026-12-01 16:14   ` Boris Brezillon
2026-12-01 16:20     ` Boris Brezillon
2026-12-01 16:28       ` Tvrtko Ursulin
2026-12-01 16:44         ` Boris Brezillon
2026-12-01 14:14 ` Boris Brezillon
2026-12-01 14:15 ` sashiko-bot
2026-12-01 14:40 ` Christian König
2026-12-01 15:09   ` Boris Brezillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202110914.24479237@fedora1.home \
    --to=boris.brezillon@collabora.com \
    --cc=airlied@gmail.com \
    --cc=akash.goel@arm.com \
    --cc=chris.diamand@arm.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karunika.choo@arm.com \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=liviu.dudau@arm.com \
    --cc=lukas.zapolskas@arm.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=phasta@kernel.org \
    --cc=phasta@mailbox.org \
    --cc=simona@ffwll.ch \
    --cc=steven.price@arm.com \
    --cc=sumit.semwal@linaro.org \
    --cc=tzimmermann@suse.de \
    --cc=xianzhong.li@nxp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.