[PATCH v3 1/2] drm/panthor: Explode container fences to optimize pipelining

From: Boris Brezillon

Date: Wed Dec 02 2026 - 04:00:55 EST


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. This will allow us
benefit from the pipelining provided by the ring buffer (no extra
MCU <-> CPU round-trip to have the job pushed to the ring buffer).

drm_sched_entity_add_dependency_cb() already has this optimization in
place, all we need to do is explode the chain/array containers with a
dma_fence_unwrap_for_each() when we add job dependencies.

Signed-off-by: Boris Brezillon <boris.brezillon@xxxxxxxxxxxxx>
Cc: Xianzhong Li <xianzhong.li@xxxxxxx>
---
drivers/gpu/drm/panthor/panthor_drv.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index dc8d0191aef4..79c994aa1b3a 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>
@@ -612,8 +613,8 @@ panthor_submit_ctx_add_sync_deps_to_job(struct panthor_submit_ctx *ctx,
int ret = 0;

for (u32 i = 0; i < sync_op_count; i++) {
+ struct dma_fence *fence, *inner_fence;
struct panthor_sync_signal *sig_sync;
- struct dma_fence *fence;

if (!sync_op_is_wait(&sync_ops[i]))
continue;
@@ -637,7 +638,16 @@ panthor_submit_ctx_add_sync_deps_to_job(struct panthor_submit_ctx *ctx,
return ret;
}

- ret = drm_sched_job_add_dependency(job, fence);
+ /* Explode containers so that drm_sched_job_add_dependency() can
+ * eliminate fences that are coming from the same queue.
+ */
+ 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);
+
if (ret)
return ret;
}

--
2.56.1