mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [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; 19+ 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] 19+ 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
                     ` (2 more replies)
  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, 3 replies; 19+ 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	[flat|nested] 19+ 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 12:21   ` Boris Brezillon
  2026-12-02 12:53   ` Philipp Stanner
  2026-12-02 11:34 ` [PATCH v4 3/3] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
  2 siblings, 2 replies; 19+ 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	[flat|nested] 19+ 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; 19+ 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	[flat|nested] 19+ 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
  2026-12-02 12:37   ` Philipp Stanner
  2026-12-02 16:52   ` Tvrtko Ursulin
  2 siblings, 1 reply; 19+ 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] 19+ 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
  2026-12-03  2:05       ` Xianzhong Li
  0 siblings, 1 reply; 19+ 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] 19+ 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 12:21   ` Boris Brezillon
  2026-12-02 12:53   ` Philipp Stanner
  1 sibling, 0 replies; 19+ 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] 19+ 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:37   ` Philipp Stanner
  2026-12-02 13:36     ` Boris Brezillon
  2026-12-02 16:52   ` Tvrtko Ursulin
  2 siblings, 1 reply; 19+ messages in thread
From: Philipp Stanner @ 2026-12-02 12:37 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

Yo Boris,

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

typo, attached *to* an entity

[…]

>  	}
> 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

Personally, I'm not a huge fan of code in headers anymore since it
makes finding things more bothersome than when it'd be concentrated in
sched_entity.c; but I'm not sure whether the kernel has a policy on
that.

> @@ -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

This reads confusing.

"entity for whose job the dependency will be set"?

> + * @fence: fence representing the dependency

Maybe call it dependency, or dep_fence?

> + *
> + * Returns true if the dependency can be skipped, false if it can't.

nit: Official kernel doc style says that the return statement should be
marked with "Return: "

> + */
> +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
> +	 */

nit:
since you're already touching it, maybe wrapp the comment to 80 chars?

> +	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;
> +	}


But otherwise cool patch. Just the other day I had been wondering why
we do that check so late currently.


Philipp

^ permalink raw reply	[flat|nested] 19+ 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 12:21   ` Boris Brezillon
@ 2026-12-02 12:53   ` Philipp Stanner
  2026-12-02 13:47     ` Boris Brezillon
  1 sibling, 1 reply; 19+ messages in thread
From: Philipp Stanner @ 2026-12-02 12:53 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

On Wed, 2026-12-02 at 12:34 +0100, Boris Brezillon wrote:
> 

[…]

> +/**
> + * 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.

Not entirely true, this is the container containing the dependencies,
not the actual dependency. Right?

Maybe just call  it "dependencies" or "deps" and below "fence" then
singular, "dep"?

> + *
> + * Note that @fence is consumed in both the success and error cases.
> + *
> + * Returns:

same nit, "Return: "

> + * 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);


But makes sense to me.

With the docu:

Reviewed-by: Philipp Stanner <phasta@kernel.org>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-02 12:37   ` Philipp Stanner
@ 2026-12-02 13:36     ` Boris Brezillon
  0 siblings, 0 replies; 19+ messages in thread
From: Boris Brezillon @ 2026-12-02 13:36 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 13:37:34 +0100
Philipp Stanner <phasta@mailbox.org> wrote:

> Yo Boris,
> 
> 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  
> 
> typo, attached *to* an entity

Will fix.

> 
> […]
> 
> >  	}
> > 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  
> 
> Personally, I'm not a huge fan of code in headers anymore since it
> makes finding things more bothersome than when it'd be concentrated in
> sched_entity.c; but I'm not sure whether the kernel has a policy on
> that.

For such simple helpers, it lets the compiler inline things directly
rather than relying on LTO to figure it out (note that if both users
were in sched_main.c, I would have put the helper there, but here we
have one caller in sched_main.c and the other one in sched_entity.c).
BTW, we have such inline helpers defined in header files spread
throughout the codebase, so I'd be surprised if it was
forbidden/discouraged. It's this sort of things where you have to trust
you own judgment (is the helper short enough, is this violating API
layering, ...). As for searching stuff in the code base, I think we
have good enough LSPs with decent IDE integration that it shouldn't
really be a problem. And for old school devs, "git grep to the rescue"
;-).

> 
> > @@ -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  
> 
> This reads confusing.
> 
> "entity for whose job the dependency will be set"?

It's still confusing, I think, especially since there's no notion of
job at this level. How about "entity that waits on this dependency"?

> 
> > + * @fence: fence representing the dependency  
> 
> Maybe call it dependency, or dep_fence?

I was just trying to be consistent with the existing helpers which name
this parameter "fence".

> 
> > + *
> > + * Returns true if the dependency can be skipped, false if it can't.  
> 
> nit: Official kernel doc style says that the return statement should be
> marked with "Return: "

Will fix.

> 
> > + */
> > +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
> > +	 */  
> 
> nit:
> since you're already touching it, maybe wrapp the comment to 80 chars?

Sure, I can do that.

> 
> > +	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;
> > +	}  
> 
> 
> But otherwise cool patch. Just the other day I had been wondering why
> we do that check so late currently.

Thanks for the review.

Boris

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 2/3] drm/sched: Add a drm_sched_job_add_dependency_unwrapped() helper
  2026-12-02 12:53   ` Philipp Stanner
@ 2026-12-02 13:47     ` Boris Brezillon
  0 siblings, 0 replies; 19+ messages in thread
From: Boris Brezillon @ 2026-12-02 13:47 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

On Wed, 02 Dec 2026 13:53:58 +0100
Philipp Stanner <phasta@mailbox.org> wrote:

> On Wed, 2026-12-02 at 12:34 +0100, Boris Brezillon wrote:
> >   
> 
> […]
> 
> > +/**
> > + * 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.  
> 
> Not entirely true, this is the container containing the dependencies,
> not the actual dependency. Right?

It can be both: if it's a container fence, it's what you say, but if
it's a singular fence, the fence is added directly to the XArray. It's a
bit hard to express that in a short sentence, unfortunately...

> 
> Maybe just call  it "dependencies" or "deps" and below "fence" then
> singular, "dep"?

Well, the fact it can be both a singular fence or a container makes me
think we should keep the naming vague enough to apply to both. When you
think about it, it is a single dependency we get passed. We just
extract non-container fences out of it when we're being passed a
container, and add the resulting fences get added the dep list.

> 
> > + *
> > + * Note that @fence is consumed in both the success and error cases.
> > + *
> > + * Returns:  
> 
> same nit, "Return: "

Will fix.

> 
> > + * 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);  
> 
> 
> But makes sense to me.
> 
> With the docu:
> 
> Reviewed-by: Philipp Stanner <phasta@kernel.org>

Thanks for the review.

Boris


^ permalink raw reply	[flat|nested] 19+ 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:37   ` Philipp Stanner
@ 2026-12-02 16:52   ` Tvrtko Ursulin
  2026-12-03  9:38     ` Boris Brezillon
  2 siblings, 1 reply; 19+ messages in thread
From: Tvrtko Ursulin @ 2026-12-02 16:52 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


On 02/12/2026 11:34, 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>
> ---
>   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;
> +	}

I did some testing today and I can confirm that this is the part which 
can eliminate most dependencies. More on why later.

What I still cannot 100% remember if at some point in the past I tried 
it and something wasn't quite safe, but at least in my today's testing 
it looked okay.

I am also unsure of and I think needs discussing is whether it makes 
sense to allow drivers to choose whether to unwrap or not, or we should 
follow the same approach for everyone.

In my testing I captured stats from one second duration of the Cyberpunk 
2077 benchmark on the Steam Deck. That's around 700 submitted jobs 
across all GPU engines. Give or take, because I wasn't super precise 
with capture start end.

I looked at these numbers:

  * How many unwrapped fences per add dep on average?
  * How many we can squash with strict same context but earlier?
  * How many we can squash with the same scheduled+finished fence check?
  * How many XArray dependecies per job on average we end up with all of 
the above scenarios.

I think the most interesting data point is actually the last one.

With the stock kernel I saw around ~0.9 XArray dep entries per job.

Squashing with this patch gets that down to ~0.3 deps per job.

Unwrapping everything and applying the new and existing filtering on top 
is pretty much the same average deps per job. Which is I think the most 
interesting number since it directly sets the limit to the reduction of 
theoretical run_job<->pop_job round-trips before job can actually get 
submitted.

(Talking about round-trips, I am slightly unclear how on panthor this 
ends up a firmware cycle? Not a workqueue cycle?)

Anway.. back to the main story - why unwrapping changes the picture so 
little? This is because ~80% of submissions are a single dep which 
unwraps to a single fence. Which means vast majority of those get 
eliminated.

And even though when I unwrapped everything I saw around ~1800 real 
fences, those ~20% of submissions with multiple deps still only resolve 
to one dependency, never to zero like single dep submission almost 
always do.

So there we have it. It seems unwrapping does not buy us much. Perhaps 
on the signaling side, given we can always resolve to a single fence 
(which I find interesting on its own), we can say it's better to unwrap 
to a single dma-fence than suffer the potentially inefficient signalling 
side of dma-fence-array or dma-fence-chain?

I guess I need to come up with a different benchmark and look at 
different metrics. Like (soft)irq/s, power, not sure.

Regards,

Tvrtko

P.S. For reference the full unwrap I tested with this patch:

diff --git a/drivers/gpu/drm/scheduler/sched_main.c 
b/drivers/gpu/drm/scheduler/sched_main.c
index ba2a06e22707..ec50be7e44a4 100644
--- a/drivers/gpu/drm/scheduler/sched_main.c
+++ b/drivers/gpu/drm/scheduler/sched_main.c
@@ -71,6 +71,7 @@
  #include <linux/sched.h>
  #include <linux/completion.h>
  #include <linux/dma-resv.h>
+#include <linux/dma-fence-unwrap.h>
  #include <uapi/linux/sched/types.h>

  #include <drm/drm_print.h>
@@ -675,34 +676,52 @@ EXPORT_SYMBOL(drm_sched_job_arm);
  int drm_sched_job_add_dependency(struct drm_sched_job *job,
  				 struct dma_fence *fence)
  {
+	struct drm_sched_entity *entity = job->entity;
+	struct dma_fence_unwrap iter;
  	struct dma_fence *entry;
-	unsigned long index;
-	u32 id = 0;
-	int ret;
+	int ret = 0;

  	if (!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.
-	 */
-	xa_for_each(&job->dependencies, index, entry) {
-		if (entry->context != fence->context)
+	dma_fence_unwrap_for_each(entry, &iter, fence) {
+		struct dma_fence *dep;
+		unsigned long index;
+		bool found = false;
+
+		if (entry->context == entity->fence_context ||
+		    entry->context == entity->fence_context + 1)
  			continue;

-		if (dma_fence_is_later(fence, entry)) {
-			dma_fence_put(entry);
-			xa_store(&job->dependencies, index, fence, GFP_KERNEL);
-		} else {
-			dma_fence_put(fence);
+		xa_for_each(&job->dependencies, index, dep) {
+			if (entry->context != dep->context)
+				continue;
+
+			found = true;
+
+			if (dma_fence_is_later(entry, dep)) {
+				xa_store(&job->dependencies, index,
+					 dma_fence_get(entry), GFP_KERNEL);
+				dma_fence_put(dep);
+			}
+
+			break;
+		}
+
+		if (!found) {
+			u32 id = 0;
+
+			ret = xa_alloc(&job->dependencies, &id,
+				       dma_fence_get(entry),
+				       xa_limit_32b, GFP_KERNEL);
+			if (ret) {
+				dma_fence_put(entry);
+				break;
+			}
  		}
-		return 0;
  	}

-	ret = xa_alloc(&job->dependencies, &id, fence, xa_limit_32b, GFP_KERNEL);
-	if (ret != 0)
-		dma_fence_put(fence);
+	dma_fence_put(fence);

  	return ret;
  }


> +
>   	/* 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.
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-02 12:20     ` Boris Brezillon
@ 2026-12-03  2:05       ` Xianzhong Li
  0 siblings, 0 replies; 19+ messages in thread
From: Xianzhong Li @ 2026-12-03  2:05 UTC (permalink / raw)
  To: Boris Brezillon, 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

Hi Boris,

Thanks for your effort on pushing forward for this kernel approach,
I agree your idea to slow down a bit, actually, I want to track performance result on each iteration at the same time,

I made a small fix on patch v2 and finished patch verification with glmark2 just now, it improves 6.6% vs 7.15% (kernel patch with can_skip_dep),
diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index 058551998aa0..3d3cc7918221 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -638,7 +638,11 @@ panthor_submit_ctx_add_sync_deps_to_job(struct panthor_submit_ctx *ctx,
                 * 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);
+                       /* drm_sched_job_add_dependency() consumes a reference,
+                        * but dma_fence_unwrap_for_each() returns borrowed
+                        * fence pointers.
+                        */
+                       ret = drm_sched_job_add_dependency(job, dma_fence_get(inner_fence));
                        if (ret) {
                                dma_fence_put(iter.chain);
                                return ret;

Of course, patch v2 is still better than the original sync-wait version(6.25%) in mesa driver, https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/46172
Since patch v4 is available now, I may skip v3 and continue patch v4 verification on NXP board with Mali GPU

Best Regards,
Xianzhong

NXP Confidential
-----Original Message-----
From: Boris Brezillon <boris.brezillon@collabora.com>
Sent: Wednesday, December 2, 2026 8:21 PM
To: Philipp Stanner <phasta@mailbox.org>
Cc: phasta@kernel.org; Steven Price <steven.price@arm.com>; Liviu Dudau <liviu.dudau@arm.com>; Akash Goel <akash.goel@arm.com>; Karunika Choo <karunika.choo@arm.com>; Lukas Zapolskas <lukas.zapolskas@arm.com>; Chris Diamand <chris.diamand@arm.com>; Maarten Lankhorst <maarten.lankhorst@linux.intel.com>; Maxime Ripard <mripard@kernel.org>; Thomas Zimmermann <tzimmermann@suse.de>; David Airlie <airlied@gmail.com>; Simona Vetter <simona@ffwll.ch>; Sumit Semwal <sumit.semwal@linaro.org>; Christian König <christian.koenig@amd.com>; dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; linux-media@vger.kernel.org; linaro-mm-sig@lists.linaro.org; Xianzhong Li <xianzhong.li@nxp.com>
Subject: Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time

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] 19+ messages in thread

* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-02 16:52   ` Tvrtko Ursulin
@ 2026-12-03  9:38     ` Boris Brezillon
  2026-12-03 10:17       ` Boris Brezillon
  0 siblings, 1 reply; 19+ messages in thread
From: Boris Brezillon @ 2026-12-03  9:38 UTC (permalink / raw)
  To: Tvrtko Ursulin
  Cc: 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, Philipp Stanner, dri-devel, linux-kernel,
	linux-media, linaro-mm-sig, Xianzhong Li

Hi Tvrtko,

On Wed, 2 Dec 2026 16:52:10 +0000
Tvrtko Ursulin <tursulin@ursulin.net> wrote:

> On 02/12/2026 11:34, 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>
> > ---
> >   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;
> > +	}  
> 
> I did some testing today and I can confirm that this is the part which 
> can eliminate most dependencies. More on why later.
> 
> What I still cannot 100% remember if at some point in the past I tried 
> it and something wasn't quite safe, but at least in my today's testing 
> it looked okay.
> 
> I am also unsure of and I think needs discussing is whether it makes 
> sense to allow drivers to choose whether to unwrap or not, or we should 
> follow the same approach for everyone.
> 
> In my testing I captured stats from one second duration of the Cyberpunk 
> 2077 benchmark on the Steam Deck. That's around 700 submitted jobs 
> across all GPU engines. Give or take, because I wasn't super precise 
> with capture start end.
> 
> I looked at these numbers:
> 
>   * How many unwrapped fences per add dep on average?
>   * How many we can squash with strict same context but earlier?
>   * How many we can squash with the same scheduled+finished fence check?
>   * How many XArray dependecies per job on average we end up with all of 
> the above scenarios.
> 
> I think the most interesting data point is actually the last one.
> 
> With the stock kernel I saw around ~0.9 XArray dep entries per job.
> 
> Squashing with this patch gets that down to ~0.3 deps per job.
> 
> Unwrapping everything and applying the new and existing filtering on top 
> is pretty much the same average deps per job. Which is I think the most 
> interesting number since it directly sets the limit to the reduction of 
> theoretical run_job<->pop_job round-trips before job can actually get 
> submitted.
> 
> (Talking about round-trips, I am slightly unclear how on panthor this 
> ends up a firmware cycle? Not a workqueue cycle?)

It's not so much that it adds a FW cycle to signal (that one exists
anyway), it's just that it potentially delays the execution of the job
because of the time it takes the CPU to service the GPU interrupt and
signal the fence


	FW queueX					CPU
							queue(job0)
	job0(signal=fence0)

				[IRQ processing latency here]

							queue(job1)
	job1(wait=fence0,signal=fence1)

instead of

	FW queueX					CPU
							queue(job0)
							queue(job1)
	job0(signal=fence0)
	job1(wait=fence0,signal=fence1)


> 
> Anway.. back to the main story - why unwrapping changes the picture so 
> little? This is because ~80% of submissions are a single dep which 
> unwraps to a single fence. Which means vast majority of those get 
> eliminated.

It might be true for Vulkan, since VkTimelineSemaphores are probably
less common than VkFence/Semaphore. But the implicit sync emulation we
have in our gallium driver manages an internal timeline for all
accesses to private BOs bound to the GPU VM. Most, if not all of the
fences bound to this timeline are coming from the same queue, meaning
the unwrapping of this timeline object likely leads to no dep being
added. According to Xianzhong that's a ~7% improvement overall on
glmark2, which is not negligible. I've also added traces to see how
often we end up with jobs with absolutely no dep, and there are scenes
where it's actually happening a lot (desktop is one of those, which
explains the 30%+ improvement reported on this particular scene and
kinda validate my theory).

> 
> And even though when I unwrapped everything I saw around ~1800 real 
> fences, those ~20% of submissions with multiple deps still only resolve 
> to one dependency, never to zero like single dep submission almost 
> always do.
> 
> So there we have it. It seems unwrapping does not buy us much. Perhaps 
> on the signaling side, given we can always resolve to a single fence 
> (which I find interesting on its own), we can say it's better to unwrap 
> to a single dma-fence than suffer the potentially inefficient signalling 
> side of dma-fence-array or dma-fence-chain?

I doubt this is where the overhead comes from given how thin a layer
chain/array fences are. My initial investigation really points towards
it being related to the fact the job can start executing sooner when
self-waits are eliminated, because the job is already queued to the ring
buffer, whereas, if you force dma_fence waits before queuing, the "IRQ
processing + work scheduling + job queuing + FW wake up" delays
add up, and the HW gets to see the job later than it would have if it
was queued ahead of time (while the GPU was still executing the previous
job on the same queue). Note that this also has an impact when there are
external deps involved, depending on the order of signaling: if the
external deps appear to be signaled earlier than the self-deps, the
array/chain is still considered not signaled, but if you explode those,
the individual self-deps would be eliminated and the job would be
queued before the GPU is done executing the previous jobs on the same
queue, which implies better pipelining.

> 
> I guess I need to come up with a different benchmark and look at 
> different metrics. Like (soft)irq/s, power, not sure.

Well, the thing is, it probably varies between drivers and depends
on different factors:

1. how HW -> CPU signaling works, and how long it takes to process
   the IRQ, schedule the work and push a job to the FW ring buffer
2. how deep the ring buffer is
3. how likely we are to have queueX -> queueX deps with no other deps
   (you seem to prove that this almost never happens on the amdgpu
   stack, but I'm sure that's true on panfrost/panthor), or even how
   external/internal deps are ordered in the chain/array
4. what the UMD does (internal timeline_syncobj, export/import SYNC_FD
   dances, ...)

I'm certainly not saying we should force the unwrapping on every driver,
and that's the very reason I was skeptical about forcing it at the
drm_sched_job_add_dependency() level.

TL;DR I really think we should start with an opt-in solution. This can
take the form of a helper, like I proposed in v2, or it can be drivers
open-coding the loop, or even an option at the entity level to change
drm_sched_job_add_dependency()'s behavior. The key here is to let each
driver decide whether it's good for them to unwrap containers. If at
some point we end up with all drivers transitioning to this model we
can consider making it the default.

Thanks for all the effort you've put into gathering those numbers on a
different HW BTW, that's really appreciated.

Regards,

Boris

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-03  9:38     ` Boris Brezillon
@ 2026-12-03 10:17       ` Boris Brezillon
  2026-12-03 10:38         ` Xianzhong Li
  0 siblings, 1 reply; 19+ messages in thread
From: Boris Brezillon @ 2026-12-03 10:17 UTC (permalink / raw)
  To: Tvrtko Ursulin
  Cc: 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, Philipp Stanner, dri-devel, linux-kernel,
	linux-media, linaro-mm-sig, Xianzhong Li

On Thu, 3 Dec 2026 10:38:33 +0100
Boris Brezillon <boris.brezillon@collabora.com> wrote:

> > I guess I need to come up with a different benchmark and look at 
> > different metrics. Like (soft)irq/s, power, not sure.  
> 
> Well, the thing is, it probably varies between drivers and depends
> on different factors:
> 
> 1. how HW -> CPU signaling works, and how long it takes to process
>    the IRQ, schedule the work and push a job to the FW ring buffer
> 2. how deep the ring buffer is
> 3. how likely we are to have queueX -> queueX deps with no other deps
>    (you seem to prove that this almost never happens on the amdgpu
>    stack, but I'm sure that's true on panfrost/panthor), or even how
>    external/internal deps are ordered in the chain/array
> 4. what the UMD does (internal timeline_syncobj, export/import SYNC_FD
>    dances, ...)

Forgot

  5. How beefy your CPU is => I've tested on an rk3588, which I guess
     is more powerful (more cores, higher freq) than the NXP platform
     Xianzhong is testing on, and I don't see such a huge difference
     between wrapped and unwrapped (~1.5% improvement, which is close to
     the noise we usually get between glmark runs). The tests were done
     with both devfreq and cpufreq governor set to performance, and RPM
     disabled.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-03 10:17       ` Boris Brezillon
@ 2026-12-03 10:38         ` Xianzhong Li
  2026-12-03 12:05           ` Boris Brezillon
  0 siblings, 1 reply; 19+ messages in thread
From: Xianzhong Li @ 2026-12-03 10:38 UTC (permalink / raw)
  To: Boris Brezillon, Tvrtko Ursulin
  Cc: 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, Philipp Stanner, dri-devel, linux-kernel,
	linux-media, linaro-mm-sig

Hi Boris,

I finished patch v4 patch verification with glmark2 on NXP i.MX952(GPU: Mali-G310-V2@1GHz, CPU: 4xA55@1.7GHz),
There is 7.33% improvement with patch v4, a little better than patch v1 and v2, see per-scene improvement as below

TOTAL: [1591,1596,1593.50] -> [1708,1712,1710.25], +7.33%
[build] use-vbo=false: [1512,1544,1528.00] -> [1497,1523,1510.00], -1.18%
[build] use-vbo=true: [2797,2818,2807.50] -> [2877,2945,2909.25], +3.62%
[texture] nearest: [2813,2835,2824.00] -> [2907,2966,2941.75], +4.17%
[texture] linear: [2794,2798,2796.00] -> [2905,2972,2947.00], +5.40%
[texture] mipmap: [2848,2860,2854.00] -> [2931,3032,2977.50], +4.33%
[shading] gouraud: [2131,2138,2134.50] -> [2416,2431,2423.00], +13.52%
[shading] blinn-phong-inf: [1939,1941,1940.00] -> [2209,2211,2210.00], +13.92%
[shading] phong: [1497,1502,1499.50] -> [1671,1676,1674.00], +11.64%
[shading] cel: [1355,1358,1356.50] -> [1496,1501,1499.50], +10.54%
[bump] high-poly: [873,874,873.50] -> [936,938,937.25], +7.30%
[bump] normals: [2914,2950,2932.00] -> [3021,3084,3057.25], +4.27%
[bump] height: [2773,2843,2808.00] -> [2880,2906,2893.25], +3.04%
[effect2d] 3x3: [1115,1116,1115.50] -> [1214,1220,1217.75], +9.17%
[effect2d] 5x5: [418,419,418.50] -> [433,434,433.75], +3.64%
[pulsar]: [2392,2425,2408.50] -> [2507,2540,2521.00], +4.67%
[desktop] blur: [326,326,326.00] -> [423,425,424.00], +30.06%
[desktop] shadow: [1067,1073,1070.00] -> [1189,1219,1203.00], +12.43%
[buffer] map (non-interleave): [204,208,206.00] -> [205,207,206.00], +0.00%
[buffer] subdata (non-interleave): [202,206,204.00] -> [207,208,207.25], +1.59%
[buffer] map (interleave): [324,330,327.00] -> [321,323,322.50], -1.38%
[ideas]: [577,580,578.50] -> [559,563,560.75], -3.07%
[jellyfish]: [760,760,760.00] -> [800,807,804.50], +5.86%
[terrain]: [56,57,56.50] -> [58,61,60.25], +6.64%
[shadow]: [1169,1175,1172.00] -> [1387,1395,1391.75], +18.75%
[refract]: [163,163,163.00] -> [174,177,176.00], +7.98%
[conditionals] 0/0: [2678,2702,2690.00] -> [2788,2863,2829.75], +5.20%
[conditionals] 5/0: [1934,1934,1934.00] -> [2194,2201,2197.25], +13.61%
[conditionals] 0/5: [2679,2705,2692.00] -> [2799,2842,2819.75], +4.75%
[function] low: [2384,2387,2385.50] -> [2565,2596,2578.75], +8.10%
[function] medium: [1501,1502,1501.50] -> [1669,1677,1674.25], +11.51%
[loop] fragment-loop=false: [2351,2355,2353.00] -> [2558,2573,2565.75], +9.04%
[loop] fragment-uniform=false: [2354,2359,2356.50] -> [2553,2576,2562.00], +8.72%
[loop] fragment-uniform=true: [1562,1562,1562.00] -> [1746,1752,1749.50], +12.00%

Best Regards,
Xianzhong

NXP Confidential
-----Original Message-----
From: Boris Brezillon <boris.brezillon@collabora.com>
Sent: Thursday, December 3, 2026 6:17 PM
To: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: Steven Price <steven.price@arm.com>; Liviu Dudau <liviu.dudau@arm.com>; Akash Goel <akash.goel@arm.com>; Karunika Choo <karunika.choo@arm.com>; Lukas Zapolskas <lukas.zapolskas@arm.com>; Chris Diamand <chris.diamand@arm.com>; Maarten Lankhorst <maarten.lankhorst@linux.intel.com>; Maxime Ripard <mripard@kernel.org>; Thomas Zimmermann <tzimmermann@suse.de>; David Airlie <airlied@gmail.com>; Simona Vetter <simona@ffwll.ch>; Sumit Semwal <sumit.semwal@linaro.org>; Christian König <christian.koenig@amd.com>; Philipp Stanner <phasta@kernel.org>; dri-devel@lists.freedesktop.org; linux-kernel@vger.kernel.org; linux-media@vger.kernel.org; linaro-mm-sig@lists.linaro.org; Xianzhong Li <xianzhong.li@nxp.com>
Subject: Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time

On Thu, 3 Dec 2026 10:38:33 +0100
Boris Brezillon <boris.brezillon@collabora.com> wrote:

> > I guess I need to come up with a different benchmark and look at
> > different metrics. Like (soft)irq/s, power, not sure.
>
> Well, the thing is, it probably varies between drivers and depends on
> different factors:
>
> 1. how HW -> CPU signaling works, and how long it takes to process
>    the IRQ, schedule the work and push a job to the FW ring buffer 2.
> how deep the ring buffer is 3. how likely we are to have queueX ->
> queueX deps with no other deps
>    (you seem to prove that this almost never happens on the amdgpu
>    stack, but I'm sure that's true on panfrost/panthor), or even how
>    external/internal deps are ordered in the chain/array 4. what the
> UMD does (internal timeline_syncobj, export/import SYNC_FD
>    dances, ...)

Forgot

  5. How beefy your CPU is => I've tested on an rk3588, which I guess
     is more powerful (more cores, higher freq) than the NXP platform
     Xianzhong is testing on, and I don't see such a huge difference
     between wrapped and unwrapped (~1.5% improvement, which is close to
     the noise we usually get between glmark runs). The tests were done
     with both devfreq and cpufreq governor set to performance, and RPM
     disabled.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-03 10:38         ` Xianzhong Li
@ 2026-12-03 12:05           ` Boris Brezillon
  2026-12-03 12:14             ` Tvrtko Ursulin
  0 siblings, 1 reply; 19+ messages in thread
From: Boris Brezillon @ 2026-12-03 12:05 UTC (permalink / raw)
  To: Xianzhong Li
  Cc: Tvrtko Ursulin, 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, Philipp Stanner, dri-devel,
	linux-kernel, linux-media, linaro-mm-sig

On Thu, 3 Dec 2026 10:38:54 +0000
Xianzhong Li <xianzhong.li@nxp.com> wrote:

> Hi Boris,
> 
> I finished patch v4 patch verification with glmark2 on NXP i.MX952(GPU: Mali-G310-V2@1GHz, CPU: 4xA55@1.7GHz),
> There is 7.33% improvement with patch v4, a little better than patch v1 and v2, see per-scene improvement as below
> 
> TOTAL: [1591,1596,1593.50] -> [1708,1712,1710.25], +7.33%
> [build] use-vbo=false: [1512,1544,1528.00] -> [1497,1523,1510.00], -1.18%
> [build] use-vbo=true: [2797,2818,2807.50] -> [2877,2945,2909.25], +3.62%
> [texture] nearest: [2813,2835,2824.00] -> [2907,2966,2941.75], +4.17%
> [texture] linear: [2794,2798,2796.00] -> [2905,2972,2947.00], +5.40%
> [texture] mipmap: [2848,2860,2854.00] -> [2931,3032,2977.50], +4.33%
> [shading] gouraud: [2131,2138,2134.50] -> [2416,2431,2423.00], +13.52%
> [shading] blinn-phong-inf: [1939,1941,1940.00] -> [2209,2211,2210.00], +13.92%
> [shading] phong: [1497,1502,1499.50] -> [1671,1676,1674.00], +11.64%
> [shading] cel: [1355,1358,1356.50] -> [1496,1501,1499.50], +10.54%
> [bump] high-poly: [873,874,873.50] -> [936,938,937.25], +7.30%
> [bump] normals: [2914,2950,2932.00] -> [3021,3084,3057.25], +4.27%
> [bump] height: [2773,2843,2808.00] -> [2880,2906,2893.25], +3.04%
> [effect2d] 3x3: [1115,1116,1115.50] -> [1214,1220,1217.75], +9.17%
> [effect2d] 5x5: [418,419,418.50] -> [433,434,433.75], +3.64%
> [pulsar]: [2392,2425,2408.50] -> [2507,2540,2521.00], +4.67%
> [desktop] blur: [326,326,326.00] -> [423,425,424.00], +30.06%
> [desktop] shadow: [1067,1073,1070.00] -> [1189,1219,1203.00], +12.43%
> [buffer] map (non-interleave): [204,208,206.00] -> [205,207,206.00], +0.00%
> [buffer] subdata (non-interleave): [202,206,204.00] -> [207,208,207.25], +1.59%
> [buffer] map (interleave): [324,330,327.00] -> [321,323,322.50], -1.38%
> [ideas]: [577,580,578.50] -> [559,563,560.75], -3.07%
> [jellyfish]: [760,760,760.00] -> [800,807,804.50], +5.86%
> [terrain]: [56,57,56.50] -> [58,61,60.25], +6.64%
> [shadow]: [1169,1175,1172.00] -> [1387,1395,1391.75], +18.75%
> [refract]: [163,163,163.00] -> [174,177,176.00], +7.98%
> [conditionals] 0/0: [2678,2702,2690.00] -> [2788,2863,2829.75], +5.20%
> [conditionals] 5/0: [1934,1934,1934.00] -> [2194,2201,2197.25], +13.61%
> [conditionals] 0/5: [2679,2705,2692.00] -> [2799,2842,2819.75], +4.75%
> [function] low: [2384,2387,2385.50] -> [2565,2596,2578.75], +8.10%
> [function] medium: [1501,1502,1501.50] -> [1669,1677,1674.25], +11.51%
> [loop] fragment-loop=false: [2351,2355,2353.00] -> [2558,2573,2565.75], +9.04%
> [loop] fragment-uniform=false: [2354,2359,2356.50] -> [2553,2576,2562.00], +8.72%
> [loop] fragment-uniform=true: [1562,1562,1562.00] -> [1746,1752,1749.50], +12.00%
> 

After a few more runs on my side, I can say that scenes with relatively
high scores are just too erratic to be a useful comparison point
(significant diffs between runs on the same setup). The most
interesting ones are probably the ones with lower FPS (terrain, refract,
...), and on some of those, I can definitely see an improvement
(terrain, for instance, seems to get a 40+% boost on my rk3588 setup).
I've also run gfxbench(gl_manhattan), and got a reproducible 6-ish %
improvement there. So yeah, I confirm the container unwrapping is
helping some GL workloads, and for those which are not helped, I
couldn't spot a diff above the usual noise we see between runs.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-03 12:05           ` Boris Brezillon
@ 2026-12-03 12:14             ` Tvrtko Ursulin
  2026-12-03 13:05               ` Boris Brezillon
  0 siblings, 1 reply; 19+ messages in thread
From: Tvrtko Ursulin @ 2026-12-03 12:14 UTC (permalink / raw)
  To: Boris Brezillon, Xianzhong Li
  Cc: 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, Philipp Stanner, dri-devel, linux-kernel,
	linux-media, linaro-mm-sig


On 03/12/2026 12:05, Boris Brezillon wrote:
> On Thu, 3 Dec 2026 10:38:54 +0000
> Xianzhong Li <xianzhong.li@nxp.com> wrote:
> 
>> Hi Boris,
>>
>> I finished patch v4 patch verification with glmark2 on NXP i.MX952(GPU: Mali-G310-V2@1GHz, CPU: 4xA55@1.7GHz),
>> There is 7.33% improvement with patch v4, a little better than patch v1 and v2, see per-scene improvement as below
>>
>> TOTAL: [1591,1596,1593.50] -> [1708,1712,1710.25], +7.33%
>> [build] use-vbo=false: [1512,1544,1528.00] -> [1497,1523,1510.00], -1.18%
>> [build] use-vbo=true: [2797,2818,2807.50] -> [2877,2945,2909.25], +3.62%
>> [texture] nearest: [2813,2835,2824.00] -> [2907,2966,2941.75], +4.17%
>> [texture] linear: [2794,2798,2796.00] -> [2905,2972,2947.00], +5.40%
>> [texture] mipmap: [2848,2860,2854.00] -> [2931,3032,2977.50], +4.33%
>> [shading] gouraud: [2131,2138,2134.50] -> [2416,2431,2423.00], +13.52%
>> [shading] blinn-phong-inf: [1939,1941,1940.00] -> [2209,2211,2210.00], +13.92%
>> [shading] phong: [1497,1502,1499.50] -> [1671,1676,1674.00], +11.64%
>> [shading] cel: [1355,1358,1356.50] -> [1496,1501,1499.50], +10.54%
>> [bump] high-poly: [873,874,873.50] -> [936,938,937.25], +7.30%
>> [bump] normals: [2914,2950,2932.00] -> [3021,3084,3057.25], +4.27%
>> [bump] height: [2773,2843,2808.00] -> [2880,2906,2893.25], +3.04%
>> [effect2d] 3x3: [1115,1116,1115.50] -> [1214,1220,1217.75], +9.17%
>> [effect2d] 5x5: [418,419,418.50] -> [433,434,433.75], +3.64%
>> [pulsar]: [2392,2425,2408.50] -> [2507,2540,2521.00], +4.67%
>> [desktop] blur: [326,326,326.00] -> [423,425,424.00], +30.06%
>> [desktop] shadow: [1067,1073,1070.00] -> [1189,1219,1203.00], +12.43%
>> [buffer] map (non-interleave): [204,208,206.00] -> [205,207,206.00], +0.00%
>> [buffer] subdata (non-interleave): [202,206,204.00] -> [207,208,207.25], +1.59%
>> [buffer] map (interleave): [324,330,327.00] -> [321,323,322.50], -1.38%
>> [ideas]: [577,580,578.50] -> [559,563,560.75], -3.07%
>> [jellyfish]: [760,760,760.00] -> [800,807,804.50], +5.86%
>> [terrain]: [56,57,56.50] -> [58,61,60.25], +6.64%
>> [shadow]: [1169,1175,1172.00] -> [1387,1395,1391.75], +18.75%
>> [refract]: [163,163,163.00] -> [174,177,176.00], +7.98%
>> [conditionals] 0/0: [2678,2702,2690.00] -> [2788,2863,2829.75], +5.20%
>> [conditionals] 5/0: [1934,1934,1934.00] -> [2194,2201,2197.25], +13.61%
>> [conditionals] 0/5: [2679,2705,2692.00] -> [2799,2842,2819.75], +4.75%
>> [function] low: [2384,2387,2385.50] -> [2565,2596,2578.75], +8.10%
>> [function] medium: [1501,1502,1501.50] -> [1669,1677,1674.25], +11.51%
>> [loop] fragment-loop=false: [2351,2355,2353.00] -> [2558,2573,2565.75], +9.04%
>> [loop] fragment-uniform=false: [2354,2359,2356.50] -> [2553,2576,2562.00], +8.72%
>> [loop] fragment-uniform=true: [1562,1562,1562.00] -> [1746,1752,1749.50], +12.00%
>>
> 
> After a few more runs on my side, I can say that scenes with relatively
> high scores are just too erratic to be a useful comparison point
> (significant diffs between runs on the same setup). The most
> interesting ones are probably the ones with lower FPS (terrain, refract,
> ...), and on some of those, I can definitely see an improvement
> (terrain, for instance, seems to get a 40+% boost on my rk3588 setup).
> I've also run gfxbench(gl_manhattan), and got a reproducible 6-ish %
> improvement there. So yeah, I confirm the container unwrapping is
> helping some GL workloads, and for those which are not helped, I
> couldn't spot a diff above the usual noise we see between runs.

I am glad to hear this! Might be the smaller the CPU the bigger the gain.

Do you know if the above benchamrks see a reduction in number of deps 
after unwrapping, or it is about dma-fence-array/chain signalling 
overheads? AFAIR at least the chain is quite bad in this respect, at 
least in the pathological case when fences signal one by one with large 
enough gaps.

Regards,

Tvrtko


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH v4 1/3] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-03 12:14             ` Tvrtko Ursulin
@ 2026-12-03 13:05               ` Boris Brezillon
  0 siblings, 0 replies; 19+ messages in thread
From: Boris Brezillon @ 2026-12-03 13:05 UTC (permalink / raw)
  To: Tvrtko Ursulin
  Cc: Xianzhong Li, 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, Philipp Stanner, dri-devel,
	linux-kernel, linux-media, linaro-mm-sig

On Thu, 3 Dec 2026 12:14:44 +0000
Tvrtko Ursulin <tursulin@ursulin.net> wrote:

> On 03/12/2026 12:05, Boris Brezillon wrote:
> > On Thu, 3 Dec 2026 10:38:54 +0000
> > Xianzhong Li <xianzhong.li@nxp.com> wrote:
> >   
> >> Hi Boris,
> >>
> >> I finished patch v4 patch verification with glmark2 on NXP i.MX952(GPU: Mali-G310-V2@1GHz, CPU: 4xA55@1.7GHz),
> >> There is 7.33% improvement with patch v4, a little better than patch v1 and v2, see per-scene improvement as below
> >>
> >> TOTAL: [1591,1596,1593.50] -> [1708,1712,1710.25], +7.33%
> >> [build] use-vbo=false: [1512,1544,1528.00] -> [1497,1523,1510.00], -1.18%
> >> [build] use-vbo=true: [2797,2818,2807.50] -> [2877,2945,2909.25], +3.62%
> >> [texture] nearest: [2813,2835,2824.00] -> [2907,2966,2941.75], +4.17%
> >> [texture] linear: [2794,2798,2796.00] -> [2905,2972,2947.00], +5.40%
> >> [texture] mipmap: [2848,2860,2854.00] -> [2931,3032,2977.50], +4.33%
> >> [shading] gouraud: [2131,2138,2134.50] -> [2416,2431,2423.00], +13.52%
> >> [shading] blinn-phong-inf: [1939,1941,1940.00] -> [2209,2211,2210.00], +13.92%
> >> [shading] phong: [1497,1502,1499.50] -> [1671,1676,1674.00], +11.64%
> >> [shading] cel: [1355,1358,1356.50] -> [1496,1501,1499.50], +10.54%
> >> [bump] high-poly: [873,874,873.50] -> [936,938,937.25], +7.30%
> >> [bump] normals: [2914,2950,2932.00] -> [3021,3084,3057.25], +4.27%
> >> [bump] height: [2773,2843,2808.00] -> [2880,2906,2893.25], +3.04%
> >> [effect2d] 3x3: [1115,1116,1115.50] -> [1214,1220,1217.75], +9.17%
> >> [effect2d] 5x5: [418,419,418.50] -> [433,434,433.75], +3.64%
> >> [pulsar]: [2392,2425,2408.50] -> [2507,2540,2521.00], +4.67%
> >> [desktop] blur: [326,326,326.00] -> [423,425,424.00], +30.06%
> >> [desktop] shadow: [1067,1073,1070.00] -> [1189,1219,1203.00], +12.43%
> >> [buffer] map (non-interleave): [204,208,206.00] -> [205,207,206.00], +0.00%
> >> [buffer] subdata (non-interleave): [202,206,204.00] -> [207,208,207.25], +1.59%
> >> [buffer] map (interleave): [324,330,327.00] -> [321,323,322.50], -1.38%
> >> [ideas]: [577,580,578.50] -> [559,563,560.75], -3.07%
> >> [jellyfish]: [760,760,760.00] -> [800,807,804.50], +5.86%
> >> [terrain]: [56,57,56.50] -> [58,61,60.25], +6.64%
> >> [shadow]: [1169,1175,1172.00] -> [1387,1395,1391.75], +18.75%
> >> [refract]: [163,163,163.00] -> [174,177,176.00], +7.98%
> >> [conditionals] 0/0: [2678,2702,2690.00] -> [2788,2863,2829.75], +5.20%
> >> [conditionals] 5/0: [1934,1934,1934.00] -> [2194,2201,2197.25], +13.61%
> >> [conditionals] 0/5: [2679,2705,2692.00] -> [2799,2842,2819.75], +4.75%
> >> [function] low: [2384,2387,2385.50] -> [2565,2596,2578.75], +8.10%
> >> [function] medium: [1501,1502,1501.50] -> [1669,1677,1674.25], +11.51%
> >> [loop] fragment-loop=false: [2351,2355,2353.00] -> [2558,2573,2565.75], +9.04%
> >> [loop] fragment-uniform=false: [2354,2359,2356.50] -> [2553,2576,2562.00], +8.72%
> >> [loop] fragment-uniform=true: [1562,1562,1562.00] -> [1746,1752,1749.50], +12.00%
> >>  
> > 
> > After a few more runs on my side, I can say that scenes with relatively
> > high scores are just too erratic to be a useful comparison point
> > (significant diffs between runs on the same setup). The most
> > interesting ones are probably the ones with lower FPS (terrain, refract,
> > ...), and on some of those, I can definitely see an improvement
> > (terrain, for instance, seems to get a 40+% boost on my rk3588 setup).
> > I've also run gfxbench(gl_manhattan), and got a reproducible 6-ish %
> > improvement there. So yeah, I confirm the container unwrapping is
> > helping some GL workloads, and for those which are not helped, I
> > couldn't spot a diff above the usual noise we see between runs.  
> 
> I am glad to hear this! Might be the smaller the CPU the bigger the gain.
> 
> Do you know if the above benchamrks see a reduction in number of deps 
> after unwrapping, or it is about dma-fence-array/chain signalling 
> overheads?

After unwrapping+self-dep elimination, I sometimes end up with no deps.
Most of the time the relationship is 1:1, and occasionally 1:2 or 1:3,
but I've seen anything above that. I also don't think I've seen
reduction at all (like 2 containers being turned into a singular
fence), because it's quite rare to be passed more than one container.
The perf gain really comes from the advantageous pipelining we get by
eliminating entity self-deps. The proof is, if I'm unwrapping but
leaving the self-deps in place and forcing a
DRM_SCHED_FENCE_DONT_PIPELINE behavior, I end up with the same results
I have without unwrapping, which is expected because a container fence
is neither an entity self-dep nor a HW-queue/gpu_scheduler self-dep,
so it can't be eliminated in drm_sched_entity_add_dependency_cb().

> AFAIR at least the chain is quite bad in this respect, at 
> least in the pathological case when fences signal one by one with large 
> enough gaps.

I guess it really depends on what's in the timeline syncobj. If all deps
come from the same GPU queue, it should nicely map to a single fence at
unwrap time. If they come from different queues, you might get more
than one, but my understanding is that, as long as fences that are part
of the chain signal in a reasonable amount of time, the chain shouldn't
grow unexpectedly big, because signalled elements get collected each
time a walk happens.

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2026-12-03 13:05 UTC | newest]

Thread overview: 19+ 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 12:20     ` Boris Brezillon
2026-12-03  2:05       ` Xianzhong Li
2026-12-02 12:37   ` Philipp Stanner
2026-12-02 13:36     ` Boris Brezillon
2026-12-02 16:52   ` Tvrtko Ursulin
2026-12-03  9:38     ` Boris Brezillon
2026-12-03 10:17       ` Boris Brezillon
2026-12-03 10:38         ` Xianzhong Li
2026-12-03 12:05           ` Boris Brezillon
2026-12-03 12:14             ` Tvrtko Ursulin
2026-12-03 13:05               ` 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 12:21   ` Boris Brezillon
2026-12-02 12:53   ` Philipp Stanner
2026-12-02 13:47     ` Boris Brezillon
2026-12-02 11:34 ` [PATCH v4 3/3] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon

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®