mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3 0/2] drm/panthor: Improve job pipelining
@ 2026-12-02  9:00 Boris Brezillon
  2026-12-02  9:00 ` [PATCH v3 1/2] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
  2026-12-02  9:00 ` [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time Boris Brezillon
  0 siblings, 2 replies; 7+ messages in thread
From: Boris Brezillon @ 2026-12-02  9:00 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 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 (2):
      drm/panthor: Explode container fences to optimize pipelining
      drm/sched: Eliminate NOP dependencies at insertion time

 drivers/gpu/drm/panthor/panthor_drv.c    | 14 ++++++++++++--
 drivers/gpu/drm/scheduler/sched_entity.c |  8 +-------
 drivers/gpu/drm/scheduler/sched_main.c   |  5 +++++
 include/drm/gpu_scheduler.h              | 20 ++++++++++++++++++++
 4 files changed, 38 insertions(+), 9 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] 7+ messages in thread

* [PATCH v3 1/2] drm/panthor: Explode container fences to optimize pipelining
  2026-12-02  9:00 [PATCH v3 0/2] drm/panthor: Improve job pipelining Boris Brezillon
@ 2026-12-02  9:00 ` Boris Brezillon
  2026-12-02  9:00 ` [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time Boris Brezillon
  1 sibling, 0 replies; 7+ messages in thread
From: Boris Brezillon @ 2026-12-02  9:00 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

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>
---
 drivers/gpu/drm/panthor/panthor_drv.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/panthor/panthor_drv.c b/drivers/gpu/drm/panthor/panthor_drv.c
index dc8d0191aef4..79c994aa1b3a 100644
--- a/drivers/gpu/drm/panthor/panthor_drv.c
+++ b/drivers/gpu/drm/panthor/panthor_drv.c
@@ -7,6 +7,7 @@
 #include <asm/arch_timer.h>
 #endif
 
+#include <linux/dma-fence-unwrap.h>
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/of_platform.h>
@@ -612,8 +613,8 @@ panthor_submit_ctx_add_sync_deps_to_job(struct panthor_submit_ctx *ctx,
 	int ret = 0;
 
 	for (u32 i = 0; i < sync_op_count; i++) {
+		struct dma_fence *fence, *inner_fence;
 		struct panthor_sync_signal *sig_sync;
-		struct dma_fence *fence;
 
 		if (!sync_op_is_wait(&sync_ops[i]))
 			continue;
@@ -637,7 +638,16 @@ panthor_submit_ctx_add_sync_deps_to_job(struct panthor_submit_ctx *ctx,
 				return ret;
 		}
 
-		ret = drm_sched_job_add_dependency(job, fence);
+		/* Explode containers so that drm_sched_job_add_dependency() can
+		 * eliminate fences that are coming from the same queue.
+		 */
+		dma_fence_unwrap_for_each(inner_fence, fence) {
+			ret = drm_sched_job_add_dependency(job, dma_fence_get(inner_fence));
+			if (ret)
+				break;
+		}
+		dma_fence_put(fence);
+
 		if (ret)
 			return ret;
 	}

-- 
2.56.1


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

* [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-02  9:00 [PATCH v3 0/2] drm/panthor: Improve job pipelining Boris Brezillon
  2026-12-02  9:00 ` [PATCH v3 1/2] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
@ 2026-12-02  9:00 ` Boris Brezillon
  2026-12-02  9:11   ` Tvrtko Ursulin
  1 sibling, 1 reply; 7+ messages in thread
From: Boris Brezillon @ 2026-12-02  9:00 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_main.c   |  5 +++++
 include/drm/gpu_scheduler.h              | 20 ++++++++++++++++++++
 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_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.
diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
index 3b0978fa8cf0..b2e9f6df68e6 100644
--- a/include/drm/gpu_scheduler.h
+++ b/include/drm/gpu_scheduler.h
@@ -734,6 +734,26 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
 				   struct drm_gpu_scheduler **sched_list,
 				   unsigned int num_sched_list);
 
+/**
+ * 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;
+}
+
 /**
  * struct drm_sched_pending_job_iter - DRM scheduler pending job iterator state
  * @sched: DRM scheduler associated with pending job iterator

-- 
2.56.1


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

* Re: [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-02  9:00 ` [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time Boris Brezillon
@ 2026-12-02  9:11   ` Tvrtko Ursulin
  2026-12-02  9:28     ` Boris Brezillon
  2026-12-02 11:40     ` Boris Brezillon
  0 siblings, 2 replies; 7+ messages in thread
From: Tvrtko Ursulin @ 2026-12-02  9:11 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 09:00, 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_main.c   |  5 +++++
>   include/drm/gpu_scheduler.h              | 20 ++++++++++++++++++++
>   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_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 thought we could be braver and unwrap, snipping at the root much more 
than just the plain fences. As written it is not super exciting, but I 
am also not saying the two have to come together. It can be considered 
as a follow up.

> +	}
> +
>   	/* 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.
> diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
> index 3b0978fa8cf0..b2e9f6df68e6 100644
> --- a/include/drm/gpu_scheduler.h
> +++ b/include/drm/gpu_scheduler.h
> @@ -734,6 +734,26 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
>   				   struct drm_gpu_scheduler **sched_list,
>   				   unsigned int num_sched_list);
>   
> +/**
> + * 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;
> +}

I'd put this into sched_internal.h unless we know someone really wants 
to use it and has a good enough reason.

Regards,

Tvrtko

> +
>   /**
>    * struct drm_sched_pending_job_iter - DRM scheduler pending job iterator state
>    * @sched: DRM scheduler associated with pending job iterator
> 


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

* Re: [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-02  9:11   ` Tvrtko Ursulin
@ 2026-12-02  9:28     ` Boris Brezillon
  2026-12-02 11:40     ` Boris Brezillon
  1 sibling, 0 replies; 7+ messages in thread
From: Boris Brezillon @ 2026-12-02  9:28 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 Wed, 2 Dec 2026 09:11:02 +0000
Tvrtko Ursulin <tursulin@ursulin.net> wrote:

> On 02/12/2026 09:00, 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_main.c   |  5 +++++
> >   include/drm/gpu_scheduler.h              | 20 ++++++++++++++++++++
> >   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_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 thought we could be braver and unwrap, snipping at the root much more 
> than just the plain fences. As written it is not super exciting, but I 
> am also not saying the two have to come together. It can be considered 
> as a follow up.

Yeah, I've considered putting that in a dma_fence_unwrap_for_each()
loop, but then I realized some drivers might actually want to limit the
number of deps by keeping containers in place if they know there's no
HW pipelining to benefit from. Didn't you say you considered replacing
the xarray thing by a fence_array gathering all deps in just one mega
fence object? I assumed the use case was exactly that: only have one cb
registration at the drm_sched level. I can change that if you think all
drivers want this container extraction. Alternatively, we could make it
a drm_sched_entity option.

> 
> > +	}
> > +
> >   	/* 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.
> > diff --git a/include/drm/gpu_scheduler.h b/include/drm/gpu_scheduler.h
> > index 3b0978fa8cf0..b2e9f6df68e6 100644
> > --- a/include/drm/gpu_scheduler.h
> > +++ b/include/drm/gpu_scheduler.h
> > @@ -734,6 +734,26 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
> >   				   struct drm_gpu_scheduler **sched_list,
> >   				   unsigned int num_sched_list);
> >   
> > +/**
> > + * 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;
> > +}  
> 
> I'd put this into sched_internal.h unless we know someone really wants 
> to use it and has a good enough reason.

Nope, no particular external user in mind for this helper, I just
forgot we had sched_internal.h for those.

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

* Re: [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-02  9:11   ` Tvrtko Ursulin
  2026-12-02  9:28     ` Boris Brezillon
@ 2026-12-02 11:40     ` Boris Brezillon
  2026-12-02 12:16       ` Christian König
  1 sibling, 1 reply; 7+ messages in thread
From: Boris Brezillon @ 2026-12-02 11:40 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 Wed, 2 Dec 2026 09:11:02 +0000
Tvrtko Ursulin <tursulin@ursulin.net> wrote:

> On 02/12/2026 09:00, 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_main.c   |  5 +++++
> >   include/drm/gpu_scheduler.h              | 20 ++++++++++++++++++++
> >   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_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 thought we could be braver and unwrap, snipping at the root much more 
> than just the plain fences. As written it is not super exciting, but I 
> am also not saying the two have to come together. It can be considered 
> as a follow up.

Just sent a new version introducing a
drm_sched_job_add_dependency_unwrapped() helper so drivers don't have
to do that manually. Sorry for the fast iteration rate BTW, but I
oscillate between mesa and kernel a lot these days, and every time I
leave something unfinished on the kernel side it tends to rot and
eventually fall through cracks, so I thought this time I'd try to push
this through as fast as possible, especially since there seems to be no
controversy on the proposed changes. Please let me know if you want me
to slow things down a bit.

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

* Re: [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time
  2026-12-02 11:40     ` Boris Brezillon
@ 2026-12-02 12:16       ` Christian König
  0 siblings, 0 replies; 7+ messages in thread
From: Christian König @ 2026-12-02 12:16 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,
	Philipp Stanner, dri-devel, linux-kernel, linux-media,
	linaro-mm-sig, Xianzhong Li

On 12/2/26 12:40, Boris Brezillon wrote:
> On Wed, 2 Dec 2026 09:11:02 +0000
> Tvrtko Ursulin <tursulin@ursulin.net> wrote:
> 
>> On 02/12/2026 09:00, 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_main.c   |  5 +++++
>>>   include/drm/gpu_scheduler.h              | 20 ++++++++++++++++++++
>>>   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_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 thought we could be braver and unwrap, snipping at the root much more 
>> than just the plain fences. As written it is not super exciting, but I 
>> am also not saying the two have to come together. It can be considered 
>> as a follow up.

IIRC I tried that once and it caused problems.

The background was that you have cases where you need to have a CPU round trip between submissions to the same engine because the run_job() callback needed the information from the previous submission to correctly stitch together the current one.

I then later cleaned that up by introducing the DRM_SCHED_FENCE_DONT_PIPELINE flag, so it should work now but please keep in mind that this might cause regressions.

Regards,
Christian.

> 
> Just sent a new version introducing a
> drm_sched_job_add_dependency_unwrapped() helper so drivers don't have
> to do that manually. Sorry for the fast iteration rate BTW, but I
> oscillate between mesa and kernel a lot these days, and every time I
> leave something unfinished on the kernel side it tends to rot and
> eventually fall through cracks, so I thought this time I'd try to push
> this through as fast as possible, especially since there seems to be no
> controversy on the proposed changes. Please let me know if you want me
> to slow things down a bit.


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

end of thread, other threads:[~2026-12-02 12:16 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02  9:00 [PATCH v3 0/2] drm/panthor: Improve job pipelining Boris Brezillon
2026-12-02  9:00 ` [PATCH v3 1/2] drm/panthor: Explode container fences to optimize pipelining Boris Brezillon
2026-12-02  9:00 ` [PATCH v3 2/2] drm/sched: Eliminate NOP dependencies at insertion time Boris Brezillon
2026-12-02  9:11   ` Tvrtko Ursulin
2026-12-02  9:28     ` Boris Brezillon
2026-12-02 11:40     ` Boris Brezillon
2026-12-02 12:16       ` 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®