From: Tvrtko Ursulin <tursulin@ursulin.net>
To: Boris Brezillon <boris.brezillon@collabora.com>,
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>
Cc: "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>,
"Philipp Stanner" <phasta@kernel.org>,
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 v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
Date: Wed, 2 Dec 2026 16:52:10 +0000 [thread overview]
Message-ID: <287283e4-261b-4ebb-92a5-14d5d2a2b443@ursulin.net> (raw)
In-Reply-To: <20261202-panhtor-dep-skip-v4-1-f84482d7a49c@collabora.com>
On 02/12/2026 11:34, 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@collabora.com>
> ---
> drivers/gpu/drm/scheduler/sched_entity.c | 8 +-------
> drivers/gpu/drm/scheduler/sched_internal.h | 20 ++++++++++++++++++++
> drivers/gpu/drm/scheduler/sched_main.c | 5 +++++
> 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_internal.h b/drivers/gpu/drm/scheduler/sched_internal.h
> index 32d3ddb820be..b7afed36b915 100644
> --- a/drivers/gpu/drm/scheduler/sched_internal.h
> +++ b/drivers/gpu/drm/scheduler/sched_internal.h
> @@ -122,6 +122,26 @@ drm_sched_entity_is_ready(struct drm_sched_entity *entity)
> return true;
> }
>
> +/**
> + * 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;
> +}
> +
> void drm_sched_entity_stats_release(struct kref *kref);
>
> /**
> 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 did some testing today and I can confirm that this is the part which
can eliminate most dependencies. More on why later.
What I still cannot 100% remember if at some point in the past I tried
it and something wasn't quite safe, but at least in my today's testing
it looked okay.
I am also unsure of and I think needs discussing is whether it makes
sense to allow drivers to choose whether to unwrap or not, or we should
follow the same approach for everyone.
In my testing I captured stats from one second duration of the Cyberpunk
2077 benchmark on the Steam Deck. That's around 700 submitted jobs
across all GPU engines. Give or take, because I wasn't super precise
with capture start end.
I looked at these numbers:
* How many unwrapped fences per add dep on average?
* How many we can squash with strict same context but earlier?
* How many we can squash with the same scheduled+finished fence check?
* How many XArray dependecies per job on average we end up with all of
the above scenarios.
I think the most interesting data point is actually the last one.
With the stock kernel I saw around ~0.9 XArray dep entries per job.
Squashing with this patch gets that down to ~0.3 deps per job.
Unwrapping everything and applying the new and existing filtering on top
is pretty much the same average deps per job. Which is I think the most
interesting number since it directly sets the limit to the reduction of
theoretical run_job<->pop_job round-trips before job can actually get
submitted.
(Talking about round-trips, I am slightly unclear how on panthor this
ends up a firmware cycle? Not a workqueue cycle?)
Anway.. back to the main story - why unwrapping changes the picture so
little? This is because ~80% of submissions are a single dep which
unwraps to a single fence. Which means vast majority of those get
eliminated.
And even though when I unwrapped everything I saw around ~1800 real
fences, those ~20% of submissions with multiple deps still only resolve
to one dependency, never to zero like single dep submission almost
always do.
So there we have it. It seems unwrapping does not buy us much. Perhaps
on the signaling side, given we can always resolve to a single fence
(which I find interesting on its own), we can say it's better to unwrap
to a single dma-fence than suffer the potentially inefficient signalling
side of dma-fence-array or dma-fence-chain?
I guess I need to come up with a different benchmark and look at
different metrics. Like (soft)irq/s, power, not sure.
Regards,
Tvrtko
P.S. For reference the full unwrap I tested with this patch:
diff --git a/drivers/gpu/drm/scheduler/sched_main.c
b/drivers/gpu/drm/scheduler/sched_main.c
index ba2a06e22707..ec50be7e44a4 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -71,6 +71,7 @@
#include <linux/sched.h>
#include <linux/completion.h>
#include <linux/dma-resv.h>
+#include <linux/dma-fence-unwrap.h>
#include <uapi/linux/sched/types.h>
#include <drm/drm_print.h>
@@ -675,34 +676,52 @@ EXPORT_SYMBOL(drm_sched_job_arm);
int drm_sched_job_add_dependency(struct drm_sched_job *job,
struct dma_fence *fence)
{
+ struct drm_sched_entity *entity = job->entity;
+ struct dma_fence_unwrap iter;
struct dma_fence *entry;
- unsigned long index;
- u32 id = 0;
- int ret;
+ int ret = 0;
if (!fence)
return 0;
- /* 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.
- */
- xa_for_each(&job->dependencies, index, entry) {
- if (entry->context != fence->context)
+ dma_fence_unwrap_for_each(entry, &iter, fence) {
+ struct dma_fence *dep;
+ unsigned long index;
+ bool found = false;
+
+ if (entry->context == entity->fence_context ||
+ entry->context == entity->fence_context + 1)
continue;
- if (dma_fence_is_later(fence, entry)) {
- dma_fence_put(entry);
- xa_store(&job->dependencies, index, fence, GFP_KERNEL);
- } else {
- dma_fence_put(fence);
+ xa_for_each(&job->dependencies, index, dep) {
+ if (entry->context != dep->context)
+ continue;
+
+ found = true;
+
+ if (dma_fence_is_later(entry, dep)) {
+ xa_store(&job->dependencies, index,
+ dma_fence_get(entry), GFP_KERNEL);
+ dma_fence_put(dep);
+ }
+
+ break;
+ }
+
+ if (!found) {
+ u32 id = 0;
+
+ ret = xa_alloc(&job->dependencies, &id,
+ dma_fence_get(entry),
+ xa_limit_32b, GFP_KERNEL);
+ if (ret) {
+ dma_fence_put(entry);
+ break;
+ }
}
- return 0;
}
- ret = xa_alloc(&job->dependencies, &id, fence, xa_limit_32b, GFP_KERNEL);
- if (ret != 0)
- dma_fence_put(fence);
+ dma_fence_put(fence);
return ret;
}
> +
> /* 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.
>
next prev parent reply other threads:[~2026-12-02 16:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 11:34 [PATCH v4 0/3] drm/panthor: Improve job pipelining Boris Brezillon
2026-12-02 11:34 ` [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time Boris Brezillon
2026-12-02 11:44 ` Philipp Stanner
2026-12-02 12:20 ` Boris Brezillon
2026-12-03 2:05 ` Xianzhong Li
2026-12-02 12:37 ` Philipp Stanner
2026-12-02 13:36 ` Boris Brezillon
2026-12-02 16:52 ` Tvrtko Ursulin [this message]
2026-12-03 9:38 ` Boris Brezillon
2026-12-03 10:17 ` Boris Brezillon
2026-12-03 10:38 ` Xianzhong Li
2026-12-03 12:05 ` Boris Brezillon
2026-12-03 12:14 ` Tvrtko Ursulin
2026-12-02 11:34 ` [PATCH v4 2/3] drm/sched: Add a drm_sched_job_add_dependency_unwrapped() helper Boris Brezillon
2026-12-02 12:21 ` Boris Brezillon
2026-12-02 12:53 ` Philipp Stanner
2026-12-02 13:47 ` Boris Brezillon
2026-12-02 11:34 ` [PATCH v4 3/3] drm/panthor: Explode container fences to optimize pipelining 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=287283e4-261b-4ebb-92a5-14d5d2a2b443@ursulin.net \
--to=tursulin@ursulin.net \
--cc=airlied@gmail.com \
--cc=akash.goel@arm.com \
--cc=boris.brezillon@collabora.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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®