* [PATCH v4 0/3] drm/panthor: Improve job pipelining
@ 2026-12-02 11:34 Boris Brezillon
2026-12-02 11:34 ` [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time Boris Brezillon
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Boris Brezillon @ 2026-12-02 11:34 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Akash Goel, Karunika Choo,
Lukas Zapolskas, Chris Diamand
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Sumit Semwal, Christian König,
Philipp Stanner, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li, Boris Brezillon
Some recent effort to improve job pipelining [1] showed that the
MCU <-> CPU round-trip that lets us signal job fences adds a
non-negligible overhead, and this problem seems to be easier and
more systematically fixed if it's addressed at the KMD side, so
here's a patch doing exactly that.
[1]https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/46172
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
Changes in v4:
- Add drm_sched_job_add_dependency_unwrapped() and use it in panthor
- Move drm_sched_entity_can_skip_dependency() to sched_internal.h
- Link to v3: https://lore.kernel.org/r/20261202-panhtor-dep-skip-v3-0-81c141ee0461@collabora.com
Changes in v3:
- Fix UAF and leak
- Add a patch to move the dep-coming-from-same-entity eviction from
drm_sched_entity_add_dependency_cb() to drm_sched_job_add_dependency()
- Base things on top of the dma_fence_unwrap_for_each() refactor
- Add a patch to evict NOP deps at insertion time
- Link to v2: https://lore.kernel.org/r/20261201-panhtor-dep-skip-v2-1-1b38efda8a0d@collabora.com
Changes in v2:
- Explode container fences with dma_fence_unwrap_for_each() instead of
and rely on drm_sched_entity_add_dependency_cb() elimination instead
of open-coding it
---
Boris Brezillon (3):
drm/sched: Eliminate NOP dependencies at insertion time
drm/sched: Add a drm_sched_job_add_dependency_unwrapped() helper
drm/panthor: Explode container fences to optimize pipelining
drivers/gpu/drm/panthor/panthor_drv.c | 3 ++-
drivers/gpu/drm/scheduler/sched_entity.c | 8 +------
drivers/gpu/drm/scheduler/sched_internal.h | 20 ++++++++++++++++++
drivers/gpu/drm/scheduler/sched_main.c | 34 ++++++++++++++++++++++++++++++
include/drm/gpu_scheduler.h | 2 ++
5 files changed, 59 insertions(+), 8 deletions(-)
---
base-commit: 28f286b0dfa9610d4ee2447415e964e8bc603056
change-id: 20261201-panhtor-dep-skip-9c6a3e2f7cc7
prerequisite-message-id: <20261201165600.9415-1-christian.koenig@amd.com>
prerequisite-patch-id: d44ba41cc1e717a9618004c360c92dfd22f42a4a
Best regards,
--
Boris Brezillon <boris.brezillon@collabora.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
2026-12-02 11:34 [PATCH v4 0/3] drm/panthor: Improve job pipelining Boris Brezillon
@ 2026-12-02 11:34 ` Boris Brezillon
2026-12-02 11:44 ` Philipp Stanner
` (2 more replies)
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 11:34 ` [PATCH v4 3/3] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
2 siblings, 3 replies; 12+ messages in thread
From: Boris Brezillon @ 2026-12-02 11:34 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Akash Goel, Karunika Choo,
Lukas Zapolskas, Chris Diamand
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Sumit Semwal, Christian König,
Philipp Stanner, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li, Boris Brezillon
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;
+ }
+
/* 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.
--
2.56.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v4 2/3] drm/sched: Add a drm_sched_job_add_dependency_unwrapped() helper
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:34 ` Boris Brezillon
2026-12-02 12:21 ` Boris Brezillon
2026-12-02 12:53 ` Philipp Stanner
2026-12-02 11:34 ` [PATCH v4 3/3] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
2 siblings, 2 replies; 12+ messages in thread
From: Boris Brezillon @ 2026-12-02 11:34 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Akash Goel, Karunika Choo,
Lukas Zapolskas, Chris Diamand
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Sumit Semwal, Christian König,
Philipp Stanner, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li, Boris Brezillon
drm_sched_job_add_dependency() adds the dependency as is to the job,
but drivers like to have containers unwrapped and each individual fence
added as a dependency so they can skip same-queue dependencies and
benefit from hardware pipelining.
We don't make this behavior the default to not regress the existing
drm_sched_job_add_dependency() users. Note that
drm_sched_job_add_{resv,implicit}_dependencies() don't need this
unwrapping because it already happened at resv update time. We could
add a drm_sched_job_add_syncobj_dependency_unwrapped() variant, but
there's no known user for that yet, so let's postpone this until
someone actually needs it.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
drivers/gpu/drm/scheduler/sched_main.c | 29 +++++++++++++++++++++++++++++
include/drm/gpu_scheduler.h | 2 ++
2 files changed, 31 insertions(+)
diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
index 5f123a5e39ff..6449d74b5218 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -66,6 +66,7 @@
* This implies waiting for previously executed jobs.
*/
+#include <linux/dma-fence-unwrap.h>
#include <linux/export.h>
#include <linux/wait.h>
#include <linux/sched.h>
@@ -708,6 +709,34 @@ int drm_sched_job_add_dependency(struct drm_sched_job *job,
}
EXPORT_SYMBOL(drm_sched_job_add_dependency);
+/**
+ * drm_sched_job_add_dependency_unwrapped - unwrap the fence (if this is a
+ * container) and add the resulting fences as job dependencies
+ * @job: scheduler job to add the dependencies to
+ * @fence: the dma_fence to add to the list of dependencies.
+ *
+ * Note that @fence is consumed in both the success and error cases.
+ *
+ * Returns:
+ * 0 on success, or an error on failing to expand the array.
+ */
+int drm_sched_job_add_dependency_unwrapped(struct drm_sched_job *job,
+ struct dma_fence *fence)
+{
+ struct dma_fence *inner_fence;
+ int ret;
+
+ dma_fence_unwrap_for_each(inner_fence, fence) {
+ ret = drm_sched_job_add_dependency(job, dma_fence_get(inner_fence));
+ if (ret)
+ break;
+ }
+
+ dma_fence_put(fence);
+ return ret;
+}
+EXPORT_SYMBOL(drm_sched_job_add_dependency_unwrapped);
+
/**
* drm_sched_job_add_syncobj_dependency - adds a syncobj's fence as a job dependency
* @job: scheduler job to add the dependencies to
diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
index 3b0978fa8cf0..5308f53d3168 100644
--- a/include/drm/gpu_scheduler.h
+++ b/include/drm/gpu_scheduler.h
@@ -694,6 +694,8 @@ void drm_sched_job_arm(struct drm_sched_job *job);
void drm_sched_entity_push_job(struct drm_sched_job *sched_job);
int drm_sched_job_add_dependency(struct drm_sched_job *job,
struct dma_fence *fence);
+int drm_sched_job_add_dependency_unwrapped(struct drm_sched_job *job,
+ struct dma_fence *fence);
int drm_sched_job_add_syncobj_dependency(struct drm_sched_job *job,
struct drm_file *file,
u32 handle,
--
2.56.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v4 3/3] drm/panthor: Explode container fences to optimize pipelining
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:34 ` [PATCH v4 2/3] drm/sched: Add a drm_sched_job_add_dependency_unwrapped() helper Boris Brezillon
@ 2026-12-02 11:34 ` Boris Brezillon
2 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2026-12-02 11:34 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Akash Goel, Karunika Choo,
Lukas Zapolskas, Chris Diamand
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Sumit Semwal, Christian König,
Philipp Stanner, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li, Boris Brezillon
Use drm_sched_job_add_dependency_unwrapped() to benefit from the
fence-coming-from-same-queue eviction even when fence containers
are involved. In some cases, this allows to queue jobs more
agressively and benefit from the pipelining provided by the CS
ring buffer.
Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Cc: Xianzhong Li <xianzhong.li@nxp.com>
---
drivers/gpu/drm/panthor/panthor_drv.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index dc8d0191aef4..d84ca3701bbb 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -7,6 +7,7 @@
#include <asm/arch_timer.h>
#endif
+#include <linux/dma-fence-unwrap.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/of_platform.h>
@@ -637,7 +638,7 @@ panthor_submit_ctx_add_sync_deps_to_job(struct panthor_submit_ctx *ctx,
return ret;
}
- ret = drm_sched_job_add_dependency(job, fence);
+ ret = drm_sched_job_add_dependency_unwrapped(job, fence);
if (ret)
return ret;
}
--
2.56.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
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-02 12:37 ` Philipp Stanner
2026-12-02 16:52 ` Tvrtko Ursulin
2 siblings, 1 reply; 12+ messages in thread
From: Philipp Stanner @ 2026-12-02 11:44 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Sumit Semwal, Christian König,
Philipp Stanner, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li
I don't want to appear overly nitty, but could we follow the "wait 24
hours before submitting new revisions" rule?
Our inboxes aren't getting smaller these days…
Thanks
Philipp
On Wed, 2026-12-02 at 12:34 +0100, 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>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
2026-12-02 11:44 ` Philipp Stanner
@ 2026-12-02 12:20 ` Boris Brezillon
0 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2026-12-02 12:20 UTC (permalink / raw)
To: Philipp Stanner
Cc: phasta, Steven Price, Liviu Dudau, Akash Goel, Karunika Choo,
Lukas Zapolskas, Chris Diamand, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Sumit Semwal,
Christian König, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li
Hi Philipp,
On Wed, 02 Dec 2026 12:44:39 +0100
Philipp Stanner <phasta@mailbox.org> wrote:
> I don't want to appear overly nitty, but could we follow the "wait 24
> hours before submitting new revisions" rule?
Duly noted. I guess I'll go back to my other stuff and forget about
this, again. Xianzhong, if this is blocker for you, can you or someone
in your team push this forward?
Thanks,
Boris
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 2/3] drm/sched: Add a drm_sched_job_add_dependency_unwrapped() helper
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
1 sibling, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2026-12-02 12:21 UTC (permalink / raw)
To: Steven Price, Liviu Dudau, Akash Goel, Karunika Choo,
Lukas Zapolskas, Chris Diamand
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Sumit Semwal, Christian König,
Philipp Stanner, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li
On Wed, 02 Dec 2026 12:34:18 +0100
Boris Brezillon <boris.brezillon@collabora.com> wrote:
> drm_sched_job_add_dependency() adds the dependency as is to the job,
> but drivers like to have containers unwrapped and each individual fence
> added as a dependency so they can skip same-queue dependencies and
> benefit from hardware pipelining.
>
> We don't make this behavior the default to not regress the existing
> drm_sched_job_add_dependency() users. Note that
> drm_sched_job_add_{resv,implicit}_dependencies() don't need this
> unwrapping because it already happened at resv update time. We could
> add a drm_sched_job_add_syncobj_dependency_unwrapped() variant, but
> there's no known user for that yet, so let's postpone this until
> someone actually needs it.
>
> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> ---
> drivers/gpu/drm/scheduler/sched_main.c | 29 +++++++++++++++++++++++++++++
> include/drm/gpu_scheduler.h | 2 ++
> 2 files changed, 31 insertions(+)
>
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index 5f123a5e39ff..6449d74b5218 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
> @@ -66,6 +66,7 @@
> * This implies waiting for previously executed jobs.
> */
>
> +#include <linux/dma-fence-unwrap.h>
> #include <linux/export.h>
> #include <linux/wait.h>
> #include <linux/sched.h>
> @@ -708,6 +709,34 @@ int drm_sched_job_add_dependency(struct drm_sched_job *job,
> }
> EXPORT_SYMBOL(drm_sched_job_add_dependency);
>
> +/**
> + * drm_sched_job_add_dependency_unwrapped - unwrap the fence (if this is a
> + * container) and add the resulting fences as job dependencies
> + * @job: scheduler job to add the dependencies to
> + * @fence: the dma_fence to add to the list of dependencies.
> + *
> + * Note that @fence is consumed in both the success and error cases.
> + *
> + * Returns:
> + * 0 on success, or an error on failing to expand the array.
> + */
> +int drm_sched_job_add_dependency_unwrapped(struct drm_sched_job *job,
> + struct dma_fence *fence)
> +{
> + struct dma_fence *inner_fence;
> + int ret;
For the record, missing ret = 0 initialization here.
> +
> + dma_fence_unwrap_for_each(inner_fence, fence) {
> + ret = drm_sched_job_add_dependency(job, dma_fence_get(inner_fence));
> + if (ret)
> + break;
> + }
> +
> + dma_fence_put(fence);
> + return ret;
> +}
> +EXPORT_SYMBOL(drm_sched_job_add_dependency_unwrapped);
> +
> /**
> * drm_sched_job_add_syncobj_dependency - adds a syncobj's fence as a job dependency
> * @job: scheduler job to add the dependencies to
> diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
> index 3b0978fa8cf0..5308f53d3168 100644
> --- a/include/drm/gpu_scheduler.h
> +++ b/include/drm/gpu_scheduler.h
> @@ -694,6 +694,8 @@ void drm_sched_job_arm(struct drm_sched_job *job);
> void drm_sched_entity_push_job(struct drm_sched_job *sched_job);
> int drm_sched_job_add_dependency(struct drm_sched_job *job,
> struct dma_fence *fence);
> +int drm_sched_job_add_dependency_unwrapped(struct drm_sched_job *job,
> + struct dma_fence *fence);
> int drm_sched_job_add_syncobj_dependency(struct drm_sched_job *job,
> struct drm_file *file,
> u32 handle,
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
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:37 ` Philipp Stanner
2026-12-02 13:36 ` Boris Brezillon
2026-12-02 16:52 ` Tvrtko Ursulin
2 siblings, 1 reply; 12+ messages in thread
From: Philipp Stanner @ 2026-12-02 12:37 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Sumit Semwal, Christian König,
Philipp Stanner, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li
Yo Boris,
On Wed, 2026-12-02 at 12:34 +0100, 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
typo, attached *to* an entity
[…]
> }
> 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
Personally, I'm not a huge fan of code in headers anymore since it
makes finding things more bothersome than when it'd be concentrated in
sched_entity.c; but I'm not sure whether the kernel has a policy on
that.
> @@ -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
This reads confusing.
"entity for whose job the dependency will be set"?
> + * @fence: fence representing the dependency
Maybe call it dependency, or dep_fence?
> + *
> + * Returns true if the dependency can be skipped, false if it can't.
nit: Official kernel doc style says that the return statement should be
marked with "Return: "
> + */
> +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
> + */
nit:
since you're already touching it, maybe wrapp the comment to 80 chars?
> + 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;
> + }
But otherwise cool patch. Just the other day I had been wondering why
we do that check so late currently.
Philipp
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 2/3] drm/sched: Add a drm_sched_job_add_dependency_unwrapped() helper
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
1 sibling, 1 reply; 12+ messages in thread
From: Philipp Stanner @ 2026-12-02 12:53 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Sumit Semwal, Christian König,
Philipp Stanner, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li
On Wed, 2026-12-02 at 12:34 +0100, Boris Brezillon wrote:
>
[…]
> +/**
> + * drm_sched_job_add_dependency_unwrapped - unwrap the fence (if this is a
> + * container) and add the resulting fences as job dependencies
> + * @job: scheduler job to add the dependencies to
> + * @fence: the dma_fence to add to the list of dependencies.
Not entirely true, this is the container containing the dependencies,
not the actual dependency. Right?
Maybe just call it "dependencies" or "deps" and below "fence" then
singular, "dep"?
> + *
> + * Note that @fence is consumed in both the success and error cases.
> + *
> + * Returns:
same nit, "Return: "
> + * 0 on success, or an error on failing to expand the array.
> + */
> +int drm_sched_job_add_dependency_unwrapped(struct drm_sched_job *job,
> + struct dma_fence *fence)
> +{
> + struct dma_fence *inner_fence;
> + int ret;
> +
> + dma_fence_unwrap_for_each(inner_fence, fence) {
> + ret = drm_sched_job_add_dependency(job, dma_fence_get(inner_fence));
> + if (ret)
> + break;
> + }
> +
> + dma_fence_put(fence);
> + return ret;
> +}
> +EXPORT_SYMBOL(drm_sched_job_add_dependency_unwrapped);
But makes sense to me.
With the docu:
Reviewed-by: Philipp Stanner <phasta@kernel.org>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
2026-12-02 12:37 ` Philipp Stanner
@ 2026-12-02 13:36 ` Boris Brezillon
0 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2026-12-02 13:36 UTC (permalink / raw)
To: Philipp Stanner
Cc: phasta, Steven Price, Liviu Dudau, Akash Goel, Karunika Choo,
Lukas Zapolskas, Chris Diamand, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Sumit Semwal,
Christian König, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li
Hi Philipp,
On Wed, 02 Dec 2026 13:37:34 +0100
Philipp Stanner <phasta@mailbox.org> wrote:
> Yo Boris,
>
> On Wed, 2026-12-02 at 12:34 +0100, 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
>
> typo, attached *to* an entity
Will fix.
>
> […]
>
> > }
> > 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
>
> Personally, I'm not a huge fan of code in headers anymore since it
> makes finding things more bothersome than when it'd be concentrated in
> sched_entity.c; but I'm not sure whether the kernel has a policy on
> that.
For such simple helpers, it lets the compiler inline things directly
rather than relying on LTO to figure it out (note that if both users
were in sched_main.c, I would have put the helper there, but here we
have one caller in sched_main.c and the other one in sched_entity.c).
BTW, we have such inline helpers defined in header files spread
throughout the codebase, so I'd be surprised if it was
forbidden/discouraged. It's this sort of things where you have to trust
you own judgment (is the helper short enough, is this violating API
layering, ...). As for searching stuff in the code base, I think we
have good enough LSPs with decent IDE integration that it shouldn't
really be a problem. And for old school devs, "git grep to the rescue"
;-).
>
> > @@ -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
>
> This reads confusing.
>
> "entity for whose job the dependency will be set"?
It's still confusing, I think, especially since there's no notion of
job at this level. How about "entity that waits on this dependency"?
>
> > + * @fence: fence representing the dependency
>
> Maybe call it dependency, or dep_fence?
I was just trying to be consistent with the existing helpers which name
this parameter "fence".
>
> > + *
> > + * Returns true if the dependency can be skipped, false if it can't.
>
> nit: Official kernel doc style says that the return statement should be
> marked with "Return: "
Will fix.
>
> > + */
> > +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
> > + */
>
> nit:
> since you're already touching it, maybe wrapp the comment to 80 chars?
Sure, I can do that.
>
> > + 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;
> > + }
>
>
> But otherwise cool patch. Just the other day I had been wondering why
> we do that check so late currently.
Thanks for the review.
Boris
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 2/3] drm/sched: Add a drm_sched_job_add_dependency_unwrapped() helper
2026-12-02 12:53 ` Philipp Stanner
@ 2026-12-02 13:47 ` Boris Brezillon
0 siblings, 0 replies; 12+ messages in thread
From: Boris Brezillon @ 2026-12-02 13:47 UTC (permalink / raw)
To: Philipp Stanner
Cc: phasta, Steven Price, Liviu Dudau, Akash Goel, Karunika Choo,
Lukas Zapolskas, Chris Diamand, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Sumit Semwal,
Christian König, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li
On Wed, 02 Dec 2026 13:53:58 +0100
Philipp Stanner <phasta@mailbox.org> wrote:
> On Wed, 2026-12-02 at 12:34 +0100, Boris Brezillon wrote:
> >
>
> […]
>
> > +/**
> > + * drm_sched_job_add_dependency_unwrapped - unwrap the fence (if this is a
> > + * container) and add the resulting fences as job dependencies
> > + * @job: scheduler job to add the dependencies to
> > + * @fence: the dma_fence to add to the list of dependencies.
>
> Not entirely true, this is the container containing the dependencies,
> not the actual dependency. Right?
It can be both: if it's a container fence, it's what you say, but if
it's a singular fence, the fence is added directly to the XArray. It's a
bit hard to express that in a short sentence, unfortunately...
>
> Maybe just call it "dependencies" or "deps" and below "fence" then
> singular, "dep"?
Well, the fact it can be both a singular fence or a container makes me
think we should keep the naming vague enough to apply to both. When you
think about it, it is a single dependency we get passed. We just
extract non-container fences out of it when we're being passed a
container, and add the resulting fences get added the dep list.
>
> > + *
> > + * Note that @fence is consumed in both the success and error cases.
> > + *
> > + * Returns:
>
> same nit, "Return: "
Will fix.
>
> > + * 0 on success, or an error on failing to expand the array.
> > + */
> > +int drm_sched_job_add_dependency_unwrapped(struct drm_sched_job *job,
> > + struct dma_fence *fence)
> > +{
> > + struct dma_fence *inner_fence;
> > + int ret;
> > +
> > + dma_fence_unwrap_for_each(inner_fence, fence) {
> > + ret = drm_sched_job_add_dependency(job, dma_fence_get(inner_fence));
> > + if (ret)
> > + break;
> > + }
> > +
> > + dma_fence_put(fence);
> > + return ret;
> > +}
> > +EXPORT_SYMBOL(drm_sched_job_add_dependency_unwrapped);
>
>
> But makes sense to me.
>
> With the docu:
>
> Reviewed-by: Philipp Stanner <phasta@kernel.org>
Thanks for the review.
Boris
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
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:37 ` Philipp Stanner
@ 2026-12-02 16:52 ` Tvrtko Ursulin
2 siblings, 0 replies; 12+ messages in thread
From: Tvrtko Ursulin @ 2026-12-02 16:52 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Akash Goel,
Karunika Choo, Lukas Zapolskas, Chris Diamand
Cc: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
David Airlie, Simona Vetter, Sumit Semwal, Christian König,
Philipp Stanner, dri-devel, linux-kernel, linux-media,
linaro-mm-sig, Xianzhong Li
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.
>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-12-02 16:52 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-02 12:37 ` Philipp Stanner
2026-12-02 13:36 ` Boris Brezillon
2026-12-02 16:52 ` 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
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®