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 <[email protected]> Cc: Xianzhong Li <[email protected]> --- 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 --- 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 --- drivers/gpu/drm/panthor/panthor_drv.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c index dc8d0191aef4..a527ce86a113 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,9 @@ 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; + struct dma_fence_unwrap iter; if (!sync_op_is_wait(&sync_ops[i])) continue; @@ -637,9 +639,16 @@ panthor_submit_ctx_add_sync_deps_to_job(struct panthor_submit_ctx *ctx, return ret; } - ret = drm_sched_job_add_dependency(job, fence); - if (ret) - return ret; + /* Explode containers so that drm_sched_entity_add_dependency_cb() can + * eliminate fences that are coming from the same queue. + */ + dma_fence_unwrap_for_each(inner_fence, &iter, fence) { + ret = drm_sched_job_add_dependency(job, inner_fence); + if (ret) { + dma_fence_put(iter.chain); + return ret; + } + } } return 0; --- base-commit: 28f286b0dfa9610d4ee2447415e964e8bc603056 change-id: 20261201-panhtor-dep-skip-9c6a3e2f7cc7 Best regards, -- Boris Brezillon <[email protected]>
