Skip to contentSkip to conversation

drm/sched: Add helper to check job dependencies

PATCH Applied Tvrtko Ursulin 4 participants 7 messages Jan 13, 2025 – Jan 20, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 drm/sched: Add helper to check job dependencies

Lets isolate scheduler internals from drivers such as pvr which currently walks the dependency array to look for fences.

Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>
---
 drivers/gpu/drm/scheduler/sched_main.c | 23 +++++++++++++++++++++++
 include/drm/gpu_scheduler.h            |  3 ++-
 2 files changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +23 -0
index 57da84908752..e6f1f2a8e033 100644
@@ -997,6 +997,29 @@ int drm_sched_job_add_implicit_dependencies(struct drm_sched_job *job,
 }
 EXPORT_SYMBOL(drm_sched_job_add_implicit_dependencies);
 
+/**
+ * drm_sched_job_has_dependency - check whether fence is the job's dependency
+ * @job: scheduler job to check
+ * @fence: fence to look for
+ *
+ * Returns:
+ * True if @fence is found within the job's dependencies, or otherwise false.
+ */
+bool drm_sched_job_has_dependency(struct drm_sched_job *job,
+				  struct dma_fence *fence)
+{
+	struct dma_fence *f;
+	unsigned long index;
+
+	xa_for_each(&job->dependencies, index, f) {
+		if (f == fence)
+			return true;
+	}
+
+	return false;
+}
+EXPORT_SYMBOL(drm_sched_job_has_dependency);
+
 /**
  * drm_sched_job_cleanup - clean up scheduler job resources
  * @job: scheduler job to clean up
include/drm/gpu_scheduler.h +2 -1
index 95e17504e46a..d118a0a57ab1 100644
@@ -577,7 +577,8 @@ int drm_sched_job_add_resv_dependencies(struct drm_sched_job *job,
 int drm_sched_job_add_implicit_dependencies(struct drm_sched_job *job,
 					    struct drm_gem_object *obj,
 					    bool write);
-
+bool drm_sched_job_has_dependency(struct drm_sched_job *job,
+				  struct dma_fence *fence);
 
 void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
 				    struct drm_gpu_scheduler **sched_list,
Signature · 1 line
2.47.1
#1 lore raw

PATCH 2/2 drm/imagination: Use the drm_sched_job_has_dependency helper

Instead of manually peeking into the DRM scheduler implementation details lets use the previously added helper.

Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Frank Binns <[email protected]>
Cc Matt Coster <[email protected]>
---
 drivers/gpu/drm/imagination/pvr_job.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/imagination/pvr_job.c +3 -9
index 618503a212a7..1cdb3cfd058d 100644
@@ -597,8 +597,6 @@ update_job_resvs_for_each(struct pvr_job_data *job_data, u32 job_count)
 static bool can_combine_jobs(struct pvr_job *a, struct pvr_job *b)
 {
 	struct pvr_job *geom_job = a, *frag_job = b;
-	struct dma_fence *fence;
-	unsigned long index;
 
 	/* Geometry and fragment jobs can be combined if they are queued to the
 	 * same context and targeting the same HWRT.
@@ -609,13 +607,9 @@ static bool can_combine_jobs(struct pvr_job *a, struct pvr_job *b)
 	    a->hwrt != b->hwrt)
 		return false;
 
-	xa_for_each(&frag_job->base.dependencies, index, fence) {
-		/* We combine when we see an explicit geom -> frag dep. */
-		if (&geom_job->base.s_fence->scheduled == fence)
-			return true;
-	}
-
-	return false;
+	/* We combine when we see an explicit geom -> frag dep. */
+	return drm_sched_job_has_dependency(&frag_job->base,
+					    &geom_job->base.s_fence->scheduled);
 }
 
 static struct dma_fence *
Signature · 1 line
2.47.1
#2 lore raw

Re: [PATCH 2/2] drm/imagination: Use the drm_sched_job_has_dependency helper

Quoted 4 lines · Tvrtko Ursulin

Instead of manually peeking into the DRM scheduler implementation details
lets use the previously added helper.

Quoted 8 lines
Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Frank Binns <[email protected]>
Cc Matt Coster <[email protected]>

Matt, just to be sure, you're OK with me pulling those two into drm- misc-next, aren't you?

P.

Quoted 40 lines

---
 drivers/gpu/drm/imagination/pvr_job.c | 12 +++---------

 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/imagination/pvr_job.c +0 -2
index 618503a212a7..1cdb3cfd058d 100644
@@ -597,8 +597,6 @@ update_job_resvs_for_each(struct pvr_job_data
 *job_data, u32 job_count)
  static bool can_combine_jobs(struct pvr_job *a, struct pvr_job *b)
  {
  	struct pvr_job *geom_job = a, *frag_job = b;
-	struct dma_fence *fence;
-	unsigned long index;


  /* Geometry and fragment jobs can be combined if they are queued to the
  * same context and targeting the same HWRT.

drivers/gpu/drm/imagination/pvr_job.c +0 -0
@@ -609,13 +607,9 @@ static bool can_combine_jobs(struct pvr_job *a,
 struct pvr_job *b)
  	    a->hwrt != b->hwrt)
  		return false;

drivers/gpu/drm/imagination/pvr_job.c +0 -2
-	xa_for_each(&frag_job->base.dependencies, index, fence) {
-		/* We combine when we see an explicit geom -> frag

dep. */

drivers/gpu/drm/imagination/pvr_job.c +3 -5
-		if (&geom_job->base.s_fence->scheduled == fence)
-			return true;
-	}
-
-	return false;
+	/* We combine when we see an explicit geom -> frag dep. */
+	return drm_sched_job_has_dependency(&frag_job->base,
+					    &geom_job->base.s_fence-
Quoted 1 line

scheduled);

 }

 static struct dma_fence *

#3 lore raw

Re: [PATCH 2/2] drm/imagination: Use the drm_sched_job_has_dependency helper

Quoted 14 lines · Philipp Stanner
Quoted 4 lines · Tvrtko Ursulin

Instead of manually peeking into the DRM scheduler implementation details
lets use the previously added helper.

Quoted 8 lines
Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Frank Binns <[email protected]>
Cc Matt Coster <[email protected]>
Quoted 2 lines

Matt, just to be sure, you're OK with me pulling those two into drm- misc-next, aren't you?

Yup, all good! Thanks for checking :)

Signature · 2 lines
Matt Coster
E: [email protected]
Quoted 44 lines

P.

Quoted 40 lines
---
 drivers/gpu/drm/imagination/pvr_job.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
drivers/gpu/drm/imagination/pvr_job.c +0 -2
index 618503a212a7..1cdb3cfd058d 100644
@@ -597,8 +597,6 @@ update_job_resvs_for_each(struct pvr_job_data
 *job_data, u32 job_count)
 static bool can_combine_jobs(struct pvr_job *a, struct pvr_job *b)
 {
 	struct pvr_job *geom_job = a, *frag_job = b;
-	struct dma_fence *fence;
-	unsigned long index;
 
 	/* Geometry and fragment jobs can be combined if they are

queued to the

drivers/gpu/drm/imagination/pvr_job.c +0 -2
 	 * same context and targeting the same HWRT.
@@ -609,13 +607,9 @@ static bool can_combine_jobs(struct pvr_job *a,
 struct pvr_job *b)
 	    a->hwrt != b->hwrt)
 		return false;
 
-	xa_for_each(&frag_job->base.dependencies, index, fence) {
-		/* We combine when we see an explicit geom -> frag

dep. */

drivers/gpu/drm/imagination/pvr_job.c +3 -5
-		if (&geom_job->base.s_fence->scheduled == fence)
-			return true;
-	}
-
-	return false;
+	/* We combine when we see an explicit geom -> frag dep. */
+	return drm_sched_job_has_dependency(&frag_job->base,
+					    &geom_job->base.s_fence-
Quoted 1 line

scheduled);

}

static struct dma_fence *

#4 lore raw

Re: [PATCH 2/2] drm/imagination: Use the drm_sched_job_has_dependency helper

Quoted 6 lines · Matt Coster
Quoted 5 lines · Philipp Stanner
Quoted 4 lines · Tvrtko Ursulin

Instead of manually peeking into the DRM scheduler implementation details
lets use the previously added helper.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>
Cc Frank Binns <[email protected]>
Cc Matt Coster <[email protected]>

Applied to drm-misc-next

Thx
P.

Quoted 7 lines
Quoted 4 lines

Matt, just to be sure, you're OK with me pulling those two into drm-
misc-next, aren't you?

Yup, all good! Thanks for checking :)

maintainer Acked-by on v1 1/2
#5 lore raw
In reply to Tvrtko Ursulin
Quoted 9 lines · Tvrtko Ursulin

Lets isolate scheduler internals from drivers such as pvr which currently walks the dependency array to look for fences.

Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>
Quoted 53 lines
---
 drivers/gpu/drm/scheduler/sched_main.c | 23 +++++++++++++++++++++++
 include/drm/gpu_scheduler.h            |  3 ++-
 2 files changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +23 -0
index 57da84908752..e6f1f2a8e033 100644
@@ -997,6 +997,29 @@ int drm_sched_job_add_implicit_dependencies(struct drm_sched_job *job,
 }
 EXPORT_SYMBOL(drm_sched_job_add_implicit_dependencies);
 
+/**
+ * drm_sched_job_has_dependency - check whether fence is the job's dependency
+ * @job: scheduler job to check
+ * @fence: fence to look for
+ *
+ * Returns:
+ * True if @fence is found within the job's dependencies, or otherwise false.
+ */
+bool drm_sched_job_has_dependency(struct drm_sched_job *job,
+				  struct dma_fence *fence)
+{
+	struct dma_fence *f;
+	unsigned long index;
+
+	xa_for_each(&job->dependencies, index, f) {
+		if (f == fence)
+			return true;
+	}
+
+	return false;
+}
+EXPORT_SYMBOL(drm_sched_job_has_dependency);
+
 /**
  * drm_sched_job_cleanup - clean up scheduler job resources
  * @job: scheduler job to clean up
include/drm/gpu_scheduler.h +2 -1
index 95e17504e46a..d118a0a57ab1 100644
@@ -577,7 +577,8 @@ int drm_sched_job_add_resv_dependencies(struct drm_sched_job *job,
 int drm_sched_job_add_implicit_dependencies(struct drm_sched_job *job,
 					    struct drm_gem_object *obj,
 					    bool write);
-
+bool drm_sched_job_has_dependency(struct drm_sched_job *job,
+				  struct dma_fence *fence);
 
 void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
 				    struct drm_gpu_scheduler **sched_list,
#6 lore raw

Hi,

Quoted 4 lines · Danilo Krummrich
Quoted 3 lines · Tvrtko Ursulin

Lets isolate scheduler internals from drivers such as pvr which currently walks the dependency array to look for fences.

Quoted 8 lines
Quoted 6 lines
Cc Christian König <[email protected]>
Cc Danilo Krummrich <[email protected]>
Cc Matthew Brost <[email protected]>
Cc Philipp Stanner <[email protected]>

Thanks! Would you also be happy to merge the two?

Regards,

Tvrtko

Quoted 54 lines
Quoted 53 lines
---
  drivers/gpu/drm/scheduler/sched_main.c | 23 +++++++++++++++++++++++
  include/drm/gpu_scheduler.h            |  3 ++-
  2 files changed, 25 insertions(+), 1 deletion(-)
drivers/gpu/drm/scheduler/sched_main.c +23 -0
index 57da84908752..e6f1f2a8e033 100644
@@ -997,6 +997,29 @@ int drm_sched_job_add_implicit_dependencies(struct drm_sched_job *job,
  }
  EXPORT_SYMBOL(drm_sched_job_add_implicit_dependencies);
 
+/**
+ * drm_sched_job_has_dependency - check whether fence is the job's dependency
+ * @job: scheduler job to check
+ * @fence: fence to look for
+ *
+ * Returns:
+ * True if @fence is found within the job's dependencies, or otherwise false.
+ */
+bool drm_sched_job_has_dependency(struct drm_sched_job *job,
+				  struct dma_fence *fence)
+{
+	struct dma_fence *f;
+	unsigned long index;
+
+	xa_for_each(&job->dependencies, index, f) {
+		if (f == fence)
+			return true;
+	}
+
+	return false;
+}
+EXPORT_SYMBOL(drm_sched_job_has_dependency);
+
  /**
   * drm_sched_job_cleanup - clean up scheduler job resources
   * @job: scheduler job to clean up
include/drm/gpu_scheduler.h +2 -1
index 95e17504e46a..d118a0a57ab1 100644
@@ -577,7 +577,8 @@ int drm_sched_job_add_resv_dependencies(struct drm_sched_job *job,
  int drm_sched_job_add_implicit_dependencies(struct drm_sched_job *job,
  					    struct drm_gem_object *obj,
  					    bool write);
-
+bool drm_sched_job_has_dependency(struct drm_sched_job *job,
+				  struct dma_fence *fence);
 
  void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
  				    struct drm_gpu_scheduler **sched_list,