* [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
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, 1 reply; 8+ 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 related [flat|nested] 8+ 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
0 siblings, 1 reply; 8+ 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] 8+ 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; 8+ 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] 8+ 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 11:44 ` sashiko-bot
2026-12-02 12:21 ` Boris Brezillon
2026-12-02 11:34 ` [PATCH v4 3/3] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
2 siblings, 2 replies; 8+ 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 related [flat|nested] 8+ 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 11:44 ` sashiko-bot
2026-12-02 12:21 ` Boris Brezillon
1 sibling, 0 replies; 8+ messages in thread
From: sashiko-bot @ 2026-12-02 11:44 UTC (permalink / raw)
To: Boris Brezillon; +Cc: dri-devel, media-ci
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/sched: uninitialized ret in
drm_sched_job_add_dependency_unwrapped()
--
commit dc051a66949e820e818fce4b58132d8dd22aa6c7
Author: Boris Brezillon <boris.brezillon@collabora.com>
drm/sched: Add a drm_sched_job_add_dependency_unwrapped() helper
This commit adds a helper that unwraps fence containers and registers each
contained dma_fence as an individual job dependency.
> diff --git a/drivers/gpu/drm/scheduler/sched_main.c b/drivers/gpu/drm/scheduler/sched_main.c
> index 5f123a5e39ff4..6449d74b5218d 100644
> --- a/drivers/gpu/drm/scheduler/sched_main.c
> +++ b/drivers/gpu/drm/scheduler/sched_main.c
[ ... ]
> @@ -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;
> +}
[Severity: High]
Should ret be initialized to 0 here?
dma_fence_unwrap_for_each() calls the out-of-line function
dma_fence_unwrap_first() and checks inner_fence before entering the loop
body. If fence is NULL or a container yields no unsignaled inner fences,
the loop body does not run and ret is returned uninitialized, which also
triggers an uninitialized variable compiler warning.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202-panhtor-dep-skip-v4-0-f84482d7a49c@collabora.com?part=2
^ permalink raw reply [flat|nested] 8+ 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 11:44 ` sashiko-bot
@ 2026-12-02 12:21 ` Boris Brezillon
1 sibling, 0 replies; 8+ 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] 8+ 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; 8+ 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 related [flat|nested] 8+ messages in thread