* [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; 6+ 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] 6+ 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
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; 6+ 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] 6+ 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 11:34 ` [PATCH v4 3/3] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
2 siblings, 1 reply; 6+ 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] 6+ 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; 6+ 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] 6+ 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
0 siblings, 0 replies; 6+ 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] 6+ 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
0 siblings, 0 replies; 6+ 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] 6+ messages in thread
end of thread, other threads:[~2026-12-02 11:44 UTC | newest]
Thread overview: 6+ 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 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 11:34 ` [PATCH v4 3/3] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
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.