Skip to contentSkip to conversation

Some drm scheduler internal renames

PATCH In review Tvrtko Ursulin 2 participants 10 messages Nov 2, 2023 – Nov 7, 2023

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

cover Some drm scheduler internal renames

From: Tvrtko Ursulin <[email protected]>

I found some of the naming a bit incosistent and unclear so just a small attempt to clarify and tidy some of them. See what people think if my first stab improves things or not.

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>

Tvrtko Ursulin (5):
drm/sched: Rename drm_sched_get_cleanup_job to be more descriptive drm/sched: Move free worker re-queuing out of the if block drm/sched: Rename drm_sched_free_job_queue to be more descriptive drm/sched: Rename drm_sched_run_job_queue_if_ready and clarify
kerneldoc
drm/sched: Drop suffix from drm_sched_wakeup_if_can_queue

 drivers/gpu/drm/scheduler/sched_entity.c |  4 +-
 drivers/gpu/drm/scheduler/sched_main.c   | 53 ++++++++++++------------
 include/drm/gpu_scheduler.h              |  2 +-
 3 files changed, 29 insertions(+), 30 deletions(-)
Signature · 1 line
2.39.2
#1 lore raw

PATCH 1/5 drm/sched: Rename drm_sched_get_cleanup_job to be more descriptive

From: Tvrtko Ursulin <[email protected]>

"Get cleanup job" makes it sound like helper is returning a job which will execute some cleanup, or something, while the kerneldoc itself accurately says "fetch the next _finished_ job". So lets rename the helper to be self documenting.

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/scheduler/sched_main.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +9 -9
index 98b2ad54fc70..fb64b35451f5 100644
@@ -448,7 +448,7 @@ static void drm_sched_job_timedout(struct work_struct *work)
 
 	sched = container_of(work, struct drm_gpu_scheduler, work_tdr.work);
 
-	/* Protects against concurrent deletion in drm_sched_get_cleanup_job */
+	/* Protects against concurrent deletion in drm_sched_get_finished_job */
 	spin_lock(&sched->job_list_lock);
 	job = list_first_entry_or_null(&sched->pending_list,
 				       struct drm_sched_job, list);
@@ -500,9 +500,9 @@ void drm_sched_stop(struct drm_gpu_scheduler *sched, struct drm_sched_job *bad)
 
 	/*
 	 * Reinsert back the bad job here - now it's safe as
-	 * drm_sched_get_cleanup_job cannot race against us and release the
+	 * drm_sched_get_finished_job cannot race against us and release the
 	 * bad job at this point - we parked (waited for) any in progress
-	 * (earlier) cleanups and drm_sched_get_cleanup_job will not be called
+	 * (earlier) cleanups and drm_sched_get_finished_job will not be called
 	 * now until the scheduler thread is unparked.
 	 */
 	if (bad && bad->sched == sched)
@@ -960,7 +960,7 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)
 }
 
 /**
- * drm_sched_get_cleanup_job - fetch the next finished job to be destroyed
+ * drm_sched_get_finished_job - fetch the next finished job to be destroyed
  *
  * @sched: scheduler instance
  *
@@ -968,7 +968,7 @@ drm_sched_select_entity(struct drm_gpu_scheduler *sched)
  * ready for it to be destroyed.
  */
 static struct drm_sched_job *
-drm_sched_get_cleanup_job(struct drm_gpu_scheduler *sched)
+drm_sched_get_finished_job(struct drm_gpu_scheduler *sched)
 {
 	struct drm_sched_job *job, *next;
 
@@ -1059,14 +1059,14 @@ static void drm_sched_free_job_work(struct work_struct *w)
 {
 	struct drm_gpu_scheduler *sched =
 		container_of(w, struct drm_gpu_scheduler, work_free_job);
-	struct drm_sched_job *cleanup_job;
+	struct drm_sched_job *job;
 
 	if (READ_ONCE(sched->pause_submit))
 		return;
 
-	cleanup_job = drm_sched_get_cleanup_job(sched);
-	if (cleanup_job) {
-		sched->ops->free_job(cleanup_job);
+	job = drm_sched_get_finished_job(sched);
+	if (job) {
+		sched->ops->free_job(job);
 
 		drm_sched_free_job_queue_if_done(sched);
 		drm_sched_run_job_queue_if_ready(sched);
Signature · 1 line
2.39.2
#2 lore raw

PATCH 2/5 drm/sched: Move free worker re-queuing out of the if block

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Whether or not there are more jobs to clean up does not depend on the existance of the current job, given both drm_sched_get_finished_job and drm_sched_free_job_queue_if_done take and drop the job list lock. Therefore it is confusing to make it read like there is a dependency.

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/scheduler/sched_main.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +3 -4
index fb64b35451f5..e1658030613f 100644
@@ -1065,12 +1065,11 @@ static void drm_sched_free_job_work(struct work_struct *w)
 		return;
 
 	job = drm_sched_get_finished_job(sched);
-	if (job) {
+	if (job)
 		sched->ops->free_job(job);
 
-		drm_sched_free_job_queue_if_done(sched);
-		drm_sched_run_job_queue_if_ready(sched);
-	}
+	drm_sched_free_job_queue_if_done(sched);
+	drm_sched_run_job_queue_if_ready(sched);
 }
 
 /**
Signature · 1 line
2.39.2
#3 lore raw

PATCH 3/5 drm/sched: Rename drm_sched_free_job_queue to be more descriptive

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

The current name makes it sound like helper will free a queue, while what it does is it enqueues the free job worker.

Rename it to drm_sched_run_free_queue to align with existing drm_sched_run_job_queue.

Despite that creating an illusion there are two queues, while in reality there is only one, at least it creates a consistent naming for the two enqueuing helpers.

At the same time simplify the "if done" helper by dropping the suffix and adding a double underscore prefix to the one which just enqueues.

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/scheduler/sched_main.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +7 -7
index e1658030613f..f9baca20b438 100644
@@ -266,20 +266,20 @@ static void drm_sched_run_job_queue(struct drm_gpu_scheduler *sched)
 }
 
 /**
- * drm_sched_free_job_queue - enqueue free-job work
+ * __drm_sched_run_free_queue - enqueue free-job work
  * @sched: scheduler instance
  */
-static void drm_sched_free_job_queue(struct drm_gpu_scheduler *sched)
+static void __drm_sched_run_free_queue(struct drm_gpu_scheduler *sched)
 {
 	if (!READ_ONCE(sched->pause_submit))
 		queue_work(sched->submit_wq, &sched->work_free_job);
 }
 
 /**
- * drm_sched_free_job_queue_if_done - enqueue free-job work if ready
+ * drm_sched_run_free_queue - enqueue free-job work if ready
  * @sched: scheduler instance
  */
-static void drm_sched_free_job_queue_if_done(struct drm_gpu_scheduler *sched)
+static void drm_sched_run_free_queue(struct drm_gpu_scheduler *sched)
 {
 	struct drm_sched_job *job;
 
@@ -287,7 +287,7 @@ static void drm_sched_free_job_queue_if_done(struct drm_gpu_scheduler *sched)
 	job = list_first_entry_or_null(&sched->pending_list,
 				       struct drm_sched_job, list);
 	if (job && dma_fence_is_signaled(&job->s_fence->finished))
-		drm_sched_free_job_queue(sched);
+		__drm_sched_run_free_queue(sched);
 	spin_unlock(&sched->job_list_lock);
 }
 
@@ -310,7 +310,7 @@ static void drm_sched_job_done(struct drm_sched_job *s_job, int result)
 	dma_fence_get(&s_fence->finished);
 	drm_sched_fence_finished(s_fence, result);
 	dma_fence_put(&s_fence->finished);
-	drm_sched_free_job_queue(sched);
+	__drm_sched_run_free_queue(sched);
 }
 
 /**
@@ -1068,7 +1068,7 @@ static void drm_sched_free_job_work(struct work_struct *w)
 	if (job)
 		sched->ops->free_job(job);
 
-	drm_sched_free_job_queue_if_done(sched);
+	drm_sched_run_free_queue(sched);
 	drm_sched_run_job_queue_if_ready(sched);
 }
 
Signature · 1 line
2.39.2
#4 lore raw

PATCH 4/5 drm/sched: Rename drm_sched_run_job_queue_if_ready and clarify kerneldoc

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

"If ready" is not immediately clear what it means - is the scheduler ready or something else? Drop the suffix, clarify kerneldoc, and employ the same naming scheme as in drm_sched_run_free_queue:

- drm_sched_run_job_queue - enqueues if there is something to enqueue
*and* scheduler is ready (can queue)
- __drm_sched_run_job_queue - low-level helper to simply queue the job

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/scheduler/sched_main.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +8 -8
index f9baca20b438..d5ddbce68fb7 100644
@@ -256,10 +256,10 @@ drm_sched_rq_select_entity_fifo(struct drm_sched_rq *rq)
 }
 
 /**
- * drm_sched_run_job_queue - enqueue run-job work
+ * __drm_sched_run_job_queue - enqueue run-job work
  * @sched: scheduler instance
  */
-static void drm_sched_run_job_queue(struct drm_gpu_scheduler *sched)
+static void __drm_sched_run_job_queue(struct drm_gpu_scheduler *sched)
 {
 	if (!READ_ONCE(sched->pause_submit))
 		queue_work(sched->submit_wq, &sched->work_run_job);
@@ -928,7 +928,7 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched)
 void drm_sched_wakeup_if_can_queue(struct drm_gpu_scheduler *sched)
 {
 	if (drm_sched_can_queue(sched))
-		drm_sched_run_job_queue(sched);
+		__drm_sched_run_job_queue(sched);
 }
 
 /**
@@ -1041,13 +1041,13 @@ drm_sched_pick_best(struct drm_gpu_scheduler **sched_list,
 EXPORT_SYMBOL(drm_sched_pick_best);
 
 /**
- * drm_sched_run_job_queue_if_ready - enqueue run-job work if ready
+ * drm_sched_run_job_queue - enqueue run-job work if there are ready entities
  * @sched: scheduler instance
  */
-static void drm_sched_run_job_queue_if_ready(struct drm_gpu_scheduler *sched)
+static void drm_sched_run_job_queue(struct drm_gpu_scheduler *sched)
 {
 	if (drm_sched_select_entity(sched))
-		drm_sched_run_job_queue(sched);
+		__drm_sched_run_job_queue(sched);
 }
 
 /**
@@ -1069,7 +1069,7 @@ static void drm_sched_free_job_work(struct work_struct *w)
 		sched->ops->free_job(job);
 
 	drm_sched_run_free_queue(sched);
-	drm_sched_run_job_queue_if_ready(sched);
+	drm_sched_run_job_queue(sched);
 }
 
 /**
@@ -1126,7 +1126,7 @@ static void drm_sched_run_job_work(struct work_struct *w)
 	}
 
 	wake_up(&sched->job_scheduled);
-	drm_sched_run_job_queue_if_ready(sched);
+	drm_sched_run_job_queue(sched);
 }
 
 /**
Signature · 1 line
2.39.2
#5 lore raw

PATCH 5/5 drm/sched: Drop suffix from drm_sched_wakeup_if_can_queue

In reply to Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

Because a) helper is exported to other parts of the scheduler and
b) there isn't a plain drm_sched_wakeup to begin with, I think we can drop the suffix and by doing so separate the intimiate knowledge between the scheduler components a bit better.

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>
---
 drivers/gpu/drm/scheduler/sched_entity.c | 4 ++--
 drivers/gpu/drm/scheduler/sched_main.c   | 4 ++--
 include/drm/gpu_scheduler.h              | 2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +2 -2
index 409e4256f6e7..f1db63cc8198 100644
@@ -370,7 +370,7 @@ static void drm_sched_entity_wakeup(struct dma_fence *f,
 		container_of(cb, struct drm_sched_entity, cb);
 
 	drm_sched_entity_clear_dep(f, cb);
-	drm_sched_wakeup_if_can_queue(entity->rq->sched);
+	drm_sched_wakeup(entity->rq->sched);
 }
 
 /**
@@ -602,7 +602,7 @@ void drm_sched_entity_push_job(struct drm_sched_job *sched_job)
 		if (drm_sched_policy == DRM_SCHED_POLICY_FIFO)
 			drm_sched_rq_update_fifo(entity, submit_ts);
 
-		drm_sched_wakeup_if_can_queue(entity->rq->sched);
+		drm_sched_wakeup(entity->rq->sched);
 	}
 }
 EXPORT_SYMBOL(drm_sched_entity_push_job);
drivers/gpu/drm/scheduler/sched_main.c +2 -2
index d5ddbce68fb7..27843e37d9b7 100644
@@ -920,12 +920,12 @@ static bool drm_sched_can_queue(struct drm_gpu_scheduler *sched)
 }
 
 /**
- * drm_sched_wakeup_if_can_queue - Wake up the scheduler
+ * drm_sched_wakeup - Wake up the scheduler if it is ready to queue
  * @sched: scheduler instance
  *
  * Wake up the scheduler if we can queue jobs.
  */
-void drm_sched_wakeup_if_can_queue(struct drm_gpu_scheduler *sched)
+void drm_sched_wakeup(struct drm_gpu_scheduler *sched)
 {
 	if (drm_sched_can_queue(sched))
 		__drm_sched_run_job_queue(sched);
include/drm/gpu_scheduler.h +1 -1
index c1565694c0e9..43730f1ecbfd 100644
@@ -558,7 +558,7 @@ void drm_sched_entity_modify_sched(struct drm_sched_entity *entity,
 
 void drm_sched_tdr_queue_imm(struct drm_gpu_scheduler *sched);
 void drm_sched_job_cleanup(struct drm_sched_job *job);
-void drm_sched_wakeup_if_can_queue(struct drm_gpu_scheduler *sched);
+void drm_sched_wakeup(struct drm_gpu_scheduler *sched);
 bool drm_sched_wqueue_ready(struct drm_gpu_scheduler *sched);
 void drm_sched_wqueue_stop(struct drm_gpu_scheduler *sched);
 void drm_sched_wqueue_start(struct drm_gpu_scheduler *sched);
Signature · 1 line
2.39.2
#6 lore raw
In reply to Tvrtko Ursulin

Hi Tvrtko,

I only now saw this patch and I had to look for it...

Do you get a bounce from [email protected]? No? You should have.

Please don't use [email protected].

Please use [email protected], this email.

Regards,
Luben

Quoted 22 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

I found some of the naming a bit incosistent and unclear so just a small attempt to clarify and tidy some of them. See what people think if my first stab improves things or not.

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>

Tvrtko Ursulin (5):
drm/sched: Rename drm_sched_get_cleanup_job to be more descriptive drm/sched: Move free worker re-queuing out of the if block drm/sched: Rename drm_sched_free_job_queue to be more descriptive drm/sched: Rename drm_sched_run_job_queue_if_ready and clarify
kerneldoc
drm/sched: Drop suffix from drm_sched_wakeup_if_can_queue

 drivers/gpu/drm/scheduler/sched_entity.c |  4 +-
 drivers/gpu/drm/scheduler/sched_main.c   | 53 ++++++++++++------------
 include/drm/gpu_scheduler.h              |  2 +-
 3 files changed, 29 insertions(+), 30 deletions(-)
Reviewed-by on the v1 series
#7 lore raw
In reply to Tvrtko Ursulin
Quoted 17 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

I found some of the naming a bit incosistent and unclear so just a small attempt to clarify and tidy some of them. See what people think if my first stab improves things or not.

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>

Tvrtko Ursulin (5):
drm/sched: Rename drm_sched_get_cleanup_job to be more descriptive drm/sched: Move free worker re-queuing out of the if block drm/sched: Rename drm_sched_free_job_queue to be more descriptive drm/sched: Rename drm_sched_run_job_queue_if_ready and clarify
kerneldoc
drm/sched: Drop suffix from drm_sched_wakeup_if_can_queue

Quoted 5 lines
 drivers/gpu/drm/scheduler/sched_entity.c |  4 +-
 drivers/gpu/drm/scheduler/sched_main.c   | 53 ++++++++++++------------
 include/drm/gpu_scheduler.h              |  2 +-
 3 files changed, 29 insertions(+), 30 deletions(-)

Series is,

and pushed to drm-misc-next.

Thanks!

Signature · 2 lines
Regards,
Luben
#8 lore raw
Quoted 24 lines · Luben Tuikov
Quoted 17 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

I found some of the naming a bit incosistent and unclear so just a small attempt to clarify and tidy some of them. See what people think if my first stab improves things or not.

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>

Tvrtko Ursulin (5):
drm/sched: Rename drm_sched_get_cleanup_job to be more descriptive drm/sched: Move free worker re-queuing out of the if block drm/sched: Rename drm_sched_free_job_queue to be more descriptive drm/sched: Rename drm_sched_run_job_queue_if_ready and clarify
kerneldoc
drm/sched: Drop suffix from drm_sched_wakeup_if_can_queue

Quoted 5 lines
  drivers/gpu/drm/scheduler/sched_entity.c |  4 +-
  drivers/gpu/drm/scheduler/sched_main.c   | 53 ++++++++++++------------
  include/drm/gpu_scheduler.h              |  2 +-
  3 files changed, 29 insertions(+), 30 deletions(-)
Quoted 5 lines

Series is,

and pushed to drm-misc-next.

Oh thanks, I definitely did not expect that to happen so quickly, especially since it conflicts with your fix for RR and there are some other opens. But it is fine, all that can be worked on top.

Regards,

Tvrtko

#9 lore raw
Quoted 28 lines · Tvrtko Ursulin
Quoted 26 lines · Luben Tuikov
Quoted 17 lines · Tvrtko Ursulin

From: Tvrtko Ursulin <[email protected]>

I found some of the naming a bit incosistent and unclear so just a small attempt to clarify and tidy some of them. See what people think if my first stab improves things or not.

Cc Luben Tuikov <[email protected]>
Cc Matthew Brost <[email protected]>

Tvrtko Ursulin (5):
drm/sched: Rename drm_sched_get_cleanup_job to be more descriptive drm/sched: Move free worker re-queuing out of the if block drm/sched: Rename drm_sched_free_job_queue to be more descriptive drm/sched: Rename drm_sched_run_job_queue_if_ready and clarify
kerneldoc
drm/sched: Drop suffix from drm_sched_wakeup_if_can_queue

Quoted 5 lines
  drivers/gpu/drm/scheduler/sched_entity.c |  4 +-
  drivers/gpu/drm/scheduler/sched_main.c   | 53 ++++++++++++------------
  include/drm/gpu_scheduler.h              |  2 +-
  3 files changed, 29 insertions(+), 30 deletions(-)

Series is,

Quoted 7 lines
Quoted 3 lines

and pushed to drm-misc-next.

Oh thanks, I definitely did not expect that to happen so quickly, especially since it conflicts with your fix for RR and there are some other opens. But it is fine, all that can be worked on top.

Yeah, it does conflict, and it does make some changes obsolete, but your series was fine and an improvement, so might as well push it.

I'll rebase my patch on top of yours.

Signature · 2 lines
Regards,
Luben