* [PATCH v2] drm/panthor: Explode container fences to optimize pipelining
@ 2026-12-01 16:35 Boris Brezillon
2026-12-01 16:52 ` Boris Brezillon
0 siblings, 1 reply; 3+ messages in thread
From: Boris Brezillon @ 2026-12-01 16:35 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, Boris Brezillon, Xianzhong Li
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@collabora.com>
Cc: Xianzhong Li <xianzhong.li@nxp.com>
---
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 <boris.brezillon@collabora.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/panthor: Explode container fences to optimize pipelining
2026-12-01 16:35 [PATCH v2] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
@ 2026-12-01 16:52 ` Boris Brezillon
2026-12-01 17:00 ` Christian König
0 siblings, 1 reply; 3+ messages in thread
From: Boris Brezillon @ 2026-12-01 16:52 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 Tue, 01 Dec 2026 17:35:28 +0100
Boris Brezillon <boris.brezillon@collabora.com> wrote:
> 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@collabora.com>
> Cc: Xianzhong Li <xianzhong.li@nxp.com>
> ---
> 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);
Missing dma_fence_get(inner_fence) here, as reported by Sashiko.
> + if (ret) {
> + dma_fence_put(iter.chain);
> + return ret;
> + }
> + }
> }
>
> return 0;
>
> ---
> base-commit: 28f286b0dfa9610d4ee2447415e964e8bc603056
> change-id: 20261201-panhtor-dep-skip-9c6a3e2f7cc7
>
> Best regards,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] drm/panthor: Explode container fences to optimize pipelining
2026-12-01 16:52 ` Boris Brezillon
@ 2026-12-01 17:00 ` Christian König
0 siblings, 0 replies; 3+ messages in thread
From: Christian König @ 2026-12-01 17:00 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, Philipp Stanner,
dri-devel, linux-kernel, linux-media, linaro-mm-sig,
Xianzhong Li
On 12/1/26 17:52, Boris Brezillon wrote:
> On Tue, 01 Dec 2026 17:35:28 +0100
> Boris Brezillon <boris.brezillon@collabora.com> wrote:
>
>> 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@collabora.com>
>> Cc: Xianzhong Li <xianzhong.li@nxp.com>
>> ---
>> 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);
>
> Missing dma_fence_get(inner_fence) here, as reported by Sashiko.
Yeah drm_sched_job_add_dependency() consumed the fence reference.
>
>> + if (ret) {
>> + dma_fence_put(iter.chain);
I had it on my TODO list for a very long time to clean that up.
Just send you the patch which makes dma_fence_unwrap_for_each() drop the reference with a scoped guard.
Apart from the reference count your patch looks reasonable to me.
Regards,
Christian.
>> + return ret;
>> + }
>> + }
>> }
>>
>> return 0;
>>
>> ---
>> base-commit: 28f286b0dfa9610d4ee2447415e964e8bc603056
>> change-id: 20261201-panhtor-dep-skip-9c6a3e2f7cc7
>>
>> Best regards,
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-01 17:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-01 16:35 [PATCH v2] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
2026-12-01 16:52 ` Boris Brezillon
2026-12-01 17:00 ` Christian König
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®