Skip to contentSkip to conversation

drm/sched: De-clutter drm_sched_init

PATCH Applied Tvrtko Ursulin 3 participants 3 messages Jul 4, 2025

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

PATCH 1/1 drm/sched: De-clutter drm_sched_init

Move work queue allocation into a helper for a more streamlined function body.

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 | 33 ++++++++++++++++----------
 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +20 -13
index c63543132f9d..648b5d2feff8 100644
@@ -84,12 +84,6 @@
 #define CREATE_TRACE_POINTS
 #include "gpu_scheduler_trace.h"
 
-#ifdef CONFIG_LOCKDEP
-static struct lockdep_map drm_sched_lockdep_map = {
-	.name = "drm_sched_lockdep_map"
-};
-#endif
-
 int drm_sched_policy = DRM_SCHED_POLICY_FIFO;
 
 /**
@@ -1261,6 +1255,25 @@ static void drm_sched_run_job_work(struct work_struct *w)
 	drm_sched_run_job_queue(sched);
 }
 
+static struct workqueue_struct *drm_sched_alloc_wq(const char *name)
+{
+#if (IS_ENABLED(CONFIG_LOCKDEP))
+	static struct lockdep_map map = {
+		.name = "drm_sched_lockdep_map"
+	};
+
+	/*
+	 * Avoid leaking a lockdep map on each drm sched creation and
+	 * destruction by using a single lockdep map for all drm sched
+	 * allocated submit_wq.
+	 */
+
+	return alloc_ordered_workqueue_lockdep_map(name, WQ_MEM_RECLAIM, &map);
+#else
+	return alloc_ordered_workqueue(name, WQ_MEM_RECLAIM);
+#endif
+}
+
 /**
  * drm_sched_init - Init a gpu scheduler instance
  *
@@ -1301,13 +1314,7 @@ int drm_sched_init(struct drm_gpu_scheduler *sched, const struct drm_sched_init_
 		sched->submit_wq = args->submit_wq;
 		sched->own_submit_wq = false;
 	} else {
-#ifdef CONFIG_LOCKDEP
-		sched->submit_wq = alloc_ordered_workqueue_lockdep_map(args->name,
-								       WQ_MEM_RECLAIM,
-								       &drm_sched_lockdep_map);
-#else
-		sched->submit_wq = alloc_ordered_workqueue(args->name, WQ_MEM_RECLAIM);
-#endif
+		sched->submit_wq = drm_sched_alloc_wq(args->name);
 		if (!sched->submit_wq)
 			return -ENOMEM;
 
Signature · 1 line
2.48.0
Reviewed-by on v1 1/1
#1 lore raw

Hi Tvrtko,

Quoted 4 lines · Tvrtko Ursulin

Move work queue allocation into a helper for a more streamlined function body.

I just sent a r-b to this patch in the Fair Scheduler series, so:

Best Regards,
- Maíra

Quoted 8 lines
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 | 33 ++++++++++++++++----------
  1 file changed, 20 insertions(+), 13 deletions(-)
#2 lore raw
In reply to Tvrtko Ursulin
Quoted 9 lines · Tvrtko Ursulin

Move work queue allocation into a helper for a more streamlined function
body.

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

Applied to drm-misc-next.

That was quick :)

P.

Quoted 73 lines

---
 drivers/gpu/drm/scheduler/sched_main.c | 33 ++++++++++++++++-------- --

 1 file changed, 20 insertions(+), 13 deletions(-)
drivers/gpu/drm/scheduler/sched_main.c +0 -0
index c63543132f9d..648b5d2feff8 100644
@@ -84,12 +84,6 @@
  #define CREATE_TRACE_POINTS
  #include "gpu_scheduler_trace.h"

drivers/gpu/drm/scheduler/sched_main.c +0 -6
-#ifdef CONFIG_LOCKDEP
-static struct lockdep_map drm_sched_lockdep_map = {
-	.name = "drm_sched_lockdep_map"
-};
-#endif
-

 int drm_sched_policy = DRM_SCHED_POLICY_FIFO;

 /**

drivers/gpu/drm/scheduler/sched_main.c +0 -0
@@ -1261,6 +1255,25 @@ static void drm_sched_run_job_work(struct
 work_struct *w)
  	drm_sched_run_job_queue(sched);
  }

drivers/gpu/drm/scheduler/sched_main.c +9 -0
+static struct workqueue_struct *drm_sched_alloc_wq(const char *name)
+{
+#if (IS_ENABLED(CONFIG_LOCKDEP))
+	static struct lockdep_map map = {
+		.name = "drm_sched_lockdep_map"
+	};
+
+	/*
+	 * Avoid leaking a lockdep map on each drm sched creation

and

drivers/gpu/drm/scheduler/sched_main.c +1 -0
+	 * destruction by using a single lockdep map for all drm

sched

drivers/gpu/drm/scheduler/sched_main.c +4 -0
+	 * allocated submit_wq.
+	 */
+
+	return alloc_ordered_workqueue_lockdep_map(name,

WQ_MEM_RECLAIM, &map);

drivers/gpu/drm/scheduler/sched_main.c +5 -0
+#else
+	return alloc_ordered_workqueue(name, WQ_MEM_RECLAIM);
+#endif
+}
+

 /**
  * drm_sched_init - Init a gpu scheduler instance *

drivers/gpu/drm/scheduler/sched_main.c +0 -6
@@ -1301,13 +1314,7 @@ int drm_sched_init(struct drm_gpu_scheduler
 *sched, const struct drm_sched_init_
  		sched->submit_wq = args->submit_wq;
  		sched->own_submit_wq = false;
  	} else {
-#ifdef CONFIG_LOCKDEP
-		sched->submit_wq =
 alloc_ordered_workqueue_lockdep_map(args->name,
-
 								       WQ_MEM_RECLAIM,
-
 								       &drm_sched_lockdep_map);
-#else
-		sched->submit_wq = alloc_ordered_workqueue(args-
Quoted 1 line

name, WQ_MEM_RECLAIM);

drivers/gpu/drm/scheduler/sched_main.c +1 -1
-#endif
+		sched->submit_wq = drm_sched_alloc_wq(args->name);

  if (!sched->submit_wq)
  return -ENOMEM;