Skip to contentSkip to conversation

Mutex/display init tweaks

PATCH In review Lucas De Marchi 2 participants 6 messages Feb 25, 2023 – Feb 27, 2023

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

cover Mutex/display init tweaks

Small tweaks to mutex allocation and display initialization. For the display part I had a few more patches on top, but I'm unable to test it properly as display is giving a lot of warnings on my DG2 systems. And I also couldn't finish detangling the display init sequency and header deps yet. While the rest of the patches is not ready, these 2 are simple enough to go in by themselves.

Lucas De Marchi (2):
drm/xe/device: Prefer the drm-managed mutex_init drm/xe/device: Let display init in a common block

 drivers/gpu/drm/xe/xe_device.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
Signature · 1 line
2.39.0
#1 lore raw

PATCH 1/2 drm/xe/device: Prefer the drm-managed mutex_init

There's inconsistent use of mutex_init(), in xe_device_create(), with several of them never calling mutex_destroy() in xe_device_destroy(). Migrate all of them to drmm_mutex_init(), so the destroy part is automatically called.

---
 drivers/gpu/drm/xe/xe_device.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/xe/xe_device.c +10 -10
index a028efa8eebe..5e2f5d93f2ce 100644
@@ -159,7 +159,6 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)
 
 	destroy_workqueue(xe->display.hotplug.dp_wq);
 	destroy_workqueue(xe->ordered_wq);
-	mutex_destroy(&xe->persitent_engines.lock);
 	ttm_device_fini(&xe->ttm);
 }
 
@@ -196,10 +195,10 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 
 	init_waitqueue_head(&xe->ufence_wq);
 
-	mutex_init(&xe->usm.lock);
+	drmm_mutex_init(&xe->drm, &xe->usm.lock);
 	xa_init_flags(&xe->usm.asid_to_vm, XA_FLAGS_ALLOC1);
 
-	mutex_init(&xe->persitent_engines.lock);
+	drmm_mutex_init(&xe->drm, &xe->persitent_engines.lock);
 	INIT_LIST_HEAD(&xe->persitent_engines.list);
 
 	spin_lock_init(&xe->pinned.lock);
@@ -213,12 +212,12 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	/* Initialize display parts here.. */
 	spin_lock_init(&xe->display.fb_tracking.lock);
 
-	mutex_init(&xe->sb_lock);
-	mutex_init(&xe->display.backlight.lock);
-	mutex_init(&xe->display.audio.mutex);
-	mutex_init(&xe->display.wm.wm_mutex);
-	mutex_init(&xe->display.pps.mutex);
-	mutex_init(&xe->display.hdcp.comp_mutex);
+	drmm_mutex_init(&xe->drm, &xe->sb_lock);
+	drmm_mutex_init(&xe->drm, &xe->display.backlight.lock);
+	drmm_mutex_init(&xe->drm, &xe->display.audio.mutex);
+	drmm_mutex_init(&xe->drm, &xe->display.wm.wm_mutex);
+	drmm_mutex_init(&xe->drm, &xe->display.pps.mutex);
+	drmm_mutex_init(&xe->drm, &xe->display.hdcp.comp_mutex);
 	xe->enabled_irq_mask = ~0;
 
 	xe->params.invert_brightness = -1;
@@ -236,7 +235,8 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	if (err)
 		goto err;
 
-	mutex_init(&xe->mem_access.lock);
+	drmm_mutex_init(&xe->drm, &xe->mem_access.lock);
+
 	return xe;
 
 err_put:
Signature · 1 line
2.39.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [Intel-xe] [PATCH 1/2] drm/xe/device: Prefer the drm-managed mutex_init

Quoted 23 lines · Lucas De Marchi

There's inconsistent use of mutex_init(), in xe_device_create(), with several of them never calling mutex_destroy() in xe_device_destroy(). Migrate all of them to drmm_mutex_init(), so the destroy part is automatically called.

---
 drivers/gpu/drm/xe/xe_device.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/xe/xe_device.c +0 -1
index a028efa8eebe..5e2f5d93f2ce 100644
@@ -159,7 +159,6 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)
 
 	destroy_workqueue(xe->display.hotplug.dp_wq);
 	destroy_workqueue(xe->ordered_wq);
-	mutex_destroy(&xe->persitent_engines.lock);
 	ttm_device_fini(&xe->ttm);
 }
 

drivers/gpu/drm/xe/xe_device.c struct xe_device *xe_device_create(struct pci_dev *pdev, · line 202

Quoted 10 lines
drivers/gpu/drm/xe/xe_device.c +2 -2
@@ -196,10 +195,10 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 
 	init_waitqueue_head(&xe->ufence_wq);
 
-	mutex_init(&xe->usm.lock);
+	drmm_mutex_init(&xe->drm, &xe->usm.lock);
 	xa_init_flags(&xe->usm.asid_to_vm, XA_FLAGS_ALLOC1);
 
-	mutex_init(&xe->persitent_engines.lock);
+	drmm_mutex_init(&xe->drm, &xe->persitent_engines.lock);
 	INIT_LIST_HEAD(&xe->persitent_engines.list);

I'm guessing this was supposed to be "persistent" rather than "persitent?" But the typo has propagated to so many places in the code now, that changing it would need to be a separate patch.

Quoted 8 lines
drivers/gpu/drm/xe/xe_device.c +0 -2
 	spin_lock_init(&xe->pinned.lock);
@@ -213,12 +212,12 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	/* Initialize display parts here.. */
 	spin_lock_init(&xe->display.fb_tracking.lock);
 
-	mutex_init(&xe->sb_lock);
-	mutex_init(&xe->display.backlight.lock);

drivers/gpu/drm/xe/xe_device.c struct xe_device *xe_device_create(struct pci_dev *pdev, · line 220

Quoted 10 lines
drivers/gpu/drm/xe/xe_device.c +6 -4
-	mutex_init(&xe->display.audio.mutex);
-	mutex_init(&xe->display.wm.wm_mutex);
-	mutex_init(&xe->display.pps.mutex);
-	mutex_init(&xe->display.hdcp.comp_mutex);
+	drmm_mutex_init(&xe->drm, &xe->sb_lock);
+	drmm_mutex_init(&xe->drm, &xe->display.backlight.lock);
+	drmm_mutex_init(&xe->drm, &xe->display.audio.mutex);
+	drmm_mutex_init(&xe->drm, &xe->display.wm.wm_mutex);
+	drmm_mutex_init(&xe->drm, &xe->display.pps.mutex);
+	drmm_mutex_init(&xe->drm, &xe->display.hdcp.comp_mutex);

It looks like we've never bothered to destroy these in i915 either.

I sort of feel like we shouldn't even be initializing display mutexes like this in xe at all. Rather i915's shared display code should just be exposing something like an intel_display_early_init() function that will take care of doing the basic data structure setup for a 'struct intel_display' and that can be called by either driver's general init. Then when someone adds a new display mutex to i915, we don't have to go duplicate the same initialization on the Xe side as well.

Anway, we can move in that direction with future series, so not a blocker here.

Quoted 16 lines
drivers/gpu/drm/xe/xe_device.c +2 -1
 	xe->enabled_irq_mask = ~0;
 
 	xe->params.invert_brightness = -1;
@@ -236,7 +235,8 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	if (err)
 		goto err;
 
-	mutex_init(&xe->mem_access.lock);
+	drmm_mutex_init(&xe->drm, &xe->mem_access.lock);
+
 	return xe;
 
 err_put:
Signature · 1 line
2.39.0
Signature · 4 lines
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation
#3 lore raw

Re: [Intel-xe] [PATCH 1/2] drm/xe/device: Prefer the drm-managed mutex_init

Quoted 31 lines · Matt Roper
Quoted 30 lines · Lucas De Marchi

There's inconsistent use of mutex_init(), in xe_device_create(), with several of them never calling mutex_destroy() in xe_device_destroy(). Migrate all of them to drmm_mutex_init(), so the destroy part is automatically called.

---
 drivers/gpu/drm/xe/xe_device.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/xe/xe_device.c +1 -2
index a028efa8eebe..5e2f5d93f2ce 100644
@@ -159,7 +159,6 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)
 
 	destroy_workqueue(xe->display.hotplug.dp_wq);
 	destroy_workqueue(xe->ordered_wq);
-	mutex_destroy(&xe->persitent_engines.lock);
 	ttm_device_fini(&xe->ttm);
 }
 
@@ -196,10 +195,10 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 
 	init_waitqueue_head(&xe->ufence_wq);
 
-	mutex_init(&xe->usm.lock);
+	drmm_mutex_init(&xe->drm, &xe->usm.lock);
 	xa_init_flags(&xe->usm.asid_to_vm, XA_FLAGS_ALLOC1);
 
Quoted 7 lines

drivers/gpu/drm/xe/xe_device.c struct xe_device *xe_device_create(struct pci_dev *pdev, · line 202

Quoted 3 lines
drivers/gpu/drm/xe/xe_device.c +1 -1
-	mutex_init(&xe->persitent_engines.lock);
+	drmm_mutex_init(&xe->drm, &xe->persitent_engines.lock);
 	INIT_LIST_HEAD(&xe->persitent_engines.list);

I'm guessing this was supposed to be "persistent" rather than "persitent?" But the typo has propagated to so many places in the code now, that changing it would need to be a separate patch.

yep, looks like it.

Quoted 22 lines
Quoted 9 lines
drivers/gpu/drm/xe/xe_device.c +0 -2
 	spin_lock_init(&xe->pinned.lock);
@@ -213,12 +212,12 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	/* Initialize display parts here.. */
 	spin_lock_init(&xe->display.fb_tracking.lock);
 
-	mutex_init(&xe->sb_lock);
-	mutex_init(&xe->display.backlight.lock);

drivers/gpu/drm/xe/xe_device.c struct xe_device *xe_device_create(struct pci_dev *pdev, · line 220

Quoted 10 lines
drivers/gpu/drm/xe/xe_device.c +6 -4
-	mutex_init(&xe->display.audio.mutex);
-	mutex_init(&xe->display.wm.wm_mutex);
-	mutex_init(&xe->display.pps.mutex);
-	mutex_init(&xe->display.hdcp.comp_mutex);
+	drmm_mutex_init(&xe->drm, &xe->sb_lock);
+	drmm_mutex_init(&xe->drm, &xe->display.backlight.lock);
+	drmm_mutex_init(&xe->drm, &xe->display.audio.mutex);
+	drmm_mutex_init(&xe->drm, &xe->display.wm.wm_mutex);
+	drmm_mutex_init(&xe->drm, &xe->display.pps.mutex);
+	drmm_mutex_init(&xe->drm, &xe->display.hdcp.comp_mutex);

It looks like we've never bothered to destroy these in i915 either.

Quoted 7 lines

I sort of feel like we shouldn't even be initializing display mutexes like this in xe at all. Rather i915's shared display code should just be exposing something like an intel_display_early_init() function that will take care of doing the basic data structure setup for a 'struct intel_display' and that can be called by either driver's general init. Then when someone adds a new display mutex to i915, we don't have to go duplicate the same initialization on the Xe side as well.

that is exactly what I was doing with some patches on top. These 2 patches are moving it to a single block that I could take out to a

	xe->display = xe_display_create();

with the goal of leaving an opaque struct xe_display that would wrap the i915 one. I also moved the device infor stuff to be set there. Code-wise I think I got 90% of that done, but then I gave
up: too many issues were popping up with the ifdefs on the i915 side and the partial copies we did in display/ext/. I may try to revive part of that, but the overall display direction reusing i915 is not very clear for me to commit much more time on that.

Here I only sent what I had split in small sane commits.

Quoted 5 lines

Anway, we can move in that direction with future series, so not a blocker here.

thanks
Lucas De Marchi

Quoted 23 lines
Quoted 17 lines
drivers/gpu/drm/xe/xe_device.c +2 -2
 	xe->enabled_irq_mask = ~0;
 
 	xe->params.invert_brightness = -1;
@@ -236,7 +235,8 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	if (err)
 		goto err;
 
-	mutex_init(&xe->mem_access.lock);
+	drmm_mutex_init(&xe->drm, &xe->mem_access.lock);
+
 	return xe;
 
 err_put:
--

2.39.0

Signature · 4 lines
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation
#4 lore raw

PATCH 2/2 drm/xe/device: Let display init in a common block

In reply to Lucas De Marchi

Move mem_access.lock initialization up and display.hotplug.dp_wq down so all the display initializations are in a common block that can be moved elsewhere later.

Also, the goto err is not correct as it misses the drm_dev_put() to correctly unwind the actions.

---
 drivers/gpu/drm/xe/xe_device.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_device.c +6 -5
index 5e2f5d93f2ce..1e7fa507c123 100644
@@ -206,12 +206,15 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	INIT_LIST_HEAD(&xe->pinned.external_vram);
 	INIT_LIST_HEAD(&xe->pinned.evicted);
 
+	drmm_mutex_init(&xe->drm, &xe->mem_access.lock);
+
 	xe->ordered_wq = alloc_ordered_workqueue("xe-ordered-wq", 0);
-	xe->display.hotplug.dp_wq = alloc_ordered_workqueue("xe-dp", 0);
 
 	/* Initialize display parts here.. */
 	spin_lock_init(&xe->display.fb_tracking.lock);
 
+	xe->display.hotplug.dp_wq = alloc_ordered_workqueue("xe-dp", 0);
+
 	drmm_mutex_init(&xe->drm, &xe->sb_lock);
 	drmm_mutex_init(&xe->drm, &xe->display.backlight.lock);
 	drmm_mutex_init(&xe->drm, &xe->display.audio.mutex);
@@ -233,15 +236,13 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 
 	err = drmm_add_action_or_reset(&xe->drm, xe_device_destroy, NULL);
 	if (err)
-		goto err;
-
-	drmm_mutex_init(&xe->drm, &xe->mem_access.lock);
+		goto err_put;
 
 	return xe;
 
 err_put:
 	drm_dev_put(&xe->drm);
-err:
+
 	return ERR_PTR(err);
 }
 
Signature · 1 line
2.39.0
Reviewed-by on v1 2/2
#5 lore raw

Re: [Intel-xe] [PATCH 2/2] drm/xe/device: Let display init in a common block

Quoted 8 lines · Lucas De Marchi

Move mem_access.lock initialization up and display.hotplug.dp_wq down so all the display initializations are in a common block that can be moved elsewhere later.

Also, the goto err is not correct as it misses the drm_dev_put() to correctly unwind the actions.

Quoted 46 lines
---
 drivers/gpu/drm/xe/xe_device.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_device.c +6 -5
index 5e2f5d93f2ce..1e7fa507c123 100644
@@ -206,12 +206,15 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 	INIT_LIST_HEAD(&xe->pinned.external_vram);
 	INIT_LIST_HEAD(&xe->pinned.evicted);
 
+	drmm_mutex_init(&xe->drm, &xe->mem_access.lock);
+
 	xe->ordered_wq = alloc_ordered_workqueue("xe-ordered-wq", 0);
-	xe->display.hotplug.dp_wq = alloc_ordered_workqueue("xe-dp", 0);
 
 	/* Initialize display parts here.. */
 	spin_lock_init(&xe->display.fb_tracking.lock);
 
+	xe->display.hotplug.dp_wq = alloc_ordered_workqueue("xe-dp", 0);
+
 	drmm_mutex_init(&xe->drm, &xe->sb_lock);
 	drmm_mutex_init(&xe->drm, &xe->display.backlight.lock);
 	drmm_mutex_init(&xe->drm, &xe->display.audio.mutex);
@@ -233,15 +236,13 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
 
 	err = drmm_add_action_or_reset(&xe->drm, xe_device_destroy, NULL);
 	if (err)
-		goto err;
-
-	drmm_mutex_init(&xe->drm, &xe->mem_access.lock);
+		goto err_put;
 
 	return xe;
 
 err_put:
 	drm_dev_put(&xe->drm);
-err:
+
 	return ERR_PTR(err);
 }
 
Signature · 1 line
2.39.0
Signature · 4 lines
Matt Roper
Graphics Software Engineer
Linux GPU Platform Enablement
Intel Corporation