Skip to contentSkip to conversation

Use high priority scheduler workqueue for high priority rings

RFC Superseded Tvrtko Ursulin 2 participants 7 messages Dec 1

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Use high priority scheduler workqueue for high priority rings

Last patch is the headline item while three preceding ones are hopefully fixes for problems I stumbled upon while adding WQ_HIGHPRI. On those three more eyes are definitely required since the init paths can be tricky.

Smoke tested on the Steam Deck and no explosions.

Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc Timur Kristóf <[email protected]>

v2:
* Lets see if I fixed the sashiko bugs.. change log in patch 2.

Tvrtko Ursulin (4):
drm/amdgpu: Free trail_fence_offs when freeing rings drm/amdgpu: Cleanup on ring failure
drm/amdgpu: Unconfuse amdgpu_ring_init()
drm/amdgpu: Use high priority scheduler workqueue for high priority
rings

 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  | 59 ++++++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   | 92 ++++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  4 +
 4 files changed, 102 insertions(+), 54 deletions(-)
Signature · 1 line
2.56.0
#1 lore raw

RFC v2 1/4 drm/amdgpu: Free trail_fence_offs when freeing rings

Looks like ring->trail_fence_offs writeback was never freed at ring destruction time. Free it in amdgpu_ring_fini() the same way as other offsets are.

Fixes ef3e13238b5f ("drm/amdgpu: add the trailing fence per ring")
Cc Hawking Zhang <[email protected]>
Cc Jack Xiao <[email protected]>
Cc Alex Deucher <[email protected]>
Cc "Timur Kristóf" <[email protected]>
Cc "Christian König" <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -0
index 7b67e8cecca2..71cabb884ac2 100644
@@ -386,6 +386,7 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
 	amdgpu_wb_free(ring->adev, ring->wptr_offs);
 
 	amdgpu_wb_free(ring->adev, ring->cond_exe_offs);
+	amdgpu_wb_free(ring->adev, ring->trail_fence_offs);
 	amdgpu_wb_free(ring->adev, ring->fence_offs);
 
 	amdgpu_bo_free_kernel(&ring->ring_obj,
Signature · 1 line
2.56.0
#2 lore raw

RFC v2 2/4 drm/amdgpu: Cleanup on ring failure

In reply to Tvrtko Ursulin

Currently if ring init fails not all, or to better say not many, objects allocated before the failure point get freed.

amdgpu_ring_fini() already somewhat handles the cleanup of partially constructed rings so lets make it handle it fully and call it when ring init fails.

This involves marking the unallocated writeback slots so only allocated ones can be freed and exporting new amdgpu_fence_driver_fini_ring() as a counterpart to existing amdgpu_fence_driver_init_ring().

Cc Alex Deucher <[email protected]>
Cc Christian König <[email protected]>
Cc Timur Kristóf <[email protected]>

---
v2:
* Cleanup the fence driver.
* Do not double free the writeback slots.
* Return -ENOMEM when ring backup allocation fails.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 56 +++++++++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c  | 57 ++++++++++++++++-------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h  |  3 ++
 3 files changed, 76 insertions(+), 40 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +34 -22
index 58219aa04013..a16bda03a13a 100644
@@ -577,31 +577,43 @@ void amdgpu_fence_driver_isr_toggle(struct amdgpu_device *adev, bool stop)
 	}
 }
 
+/**
+ * amdgpu_fence_driver_fini_ring - fini the fence driver
+ * for the requested ring.
+ *
+ * @ring: ring to fini the fence driver on
+ *
+ * Cleanup the fence driver for the requested ring (all asics).
+ */
+void amdgpu_fence_driver_fini_ring(struct amdgpu_ring *ring)
+{
+	unsigned int i;
+
+	if (!ring || !ring->fence_drv.initialized)
+		return;
+
+	/*
+	 * Notice we check for sched.ops since there's some
+	 * override on the meaning of sched.ready by amdgpu.
+	 * The natural check would be sched.ready, which is
+	 * set as drm_sched_init() finishes...
+	 */
+	if (ring->sched.ops)
+		drm_sched_fini(&ring->sched);
+
+	for (i = 0; i <= ring->fence_drv.num_fences_mask; ++i)
+		dma_fence_put(ring->fence_drv.fences[i]);
+	kfree(ring->fence_drv.fences);
+	ring->fence_drv.fences = NULL;
+	ring->fence_drv.initialized = false;
+}
+
 void amdgpu_fence_driver_sw_fini(struct amdgpu_device *adev)
 {
-	unsigned int i, j;
+	unsigned int i;
 
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
-
-		if (!ring || !ring->fence_drv.initialized)
-			continue;
-
-		/*
-		 * Notice we check for sched.ops since there's some
-		 * override on the meaning of sched.ready by amdgpu.
-		 * The natural check would be sched.ready, which is
-		 * set as drm_sched_init() finishes...
-		 */
-		if (ring->sched.ops)
-			drm_sched_fini(&ring->sched);
-
-		for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
-			dma_fence_put(ring->fence_drv.fences[j]);
-		kfree(ring->fence_drv.fences);
-		ring->fence_drv.fences = NULL;
-		ring->fence_drv.initialized = false;
-	}
+	for (i = 0; i < AMDGPU_MAX_RINGS; i++)
+		amdgpu_fence_driver_fini_ring(adev->rings[i]);
 }
 
 /**
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +39 -18

127 lines not on this page · raw message

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +3 -0
index b2040f80b7f2..9e9565b0e286 100644
@@ -66,6 +66,8 @@ enum amdgpu_ring_priority_level {
 /* Ensure the execution in case of preemption or reset */
 #define AMDGPU_FENCE_FLAG_EXEC          (1 << 3)
 
+#define AMDGPU_RING_WB_INVALID (~0u)
+
 #define to_amdgpu_ring(s) container_of((s), struct amdgpu_ring, sched)
 
 enum amdgpu_ring_type {
@@ -163,6 +165,7 @@ void amdgpu_ring_set_fence_errors_and_reemit(struct amdgpu_ring *ring,
 					     struct amdgpu_fence *guilty_fence);
 
 int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring);
+void amdgpu_fence_driver_fini_ring(struct amdgpu_ring *ring);
 int amdgpu_fence_driver_start_ring(struct amdgpu_ring *ring,
 				   struct amdgpu_irq_src *irq_src,
 				   unsigned irq_type);
Signature · 1 line
2.56.0
#3 lore raw

Re: [RFC v2 2/4] drm/amdgpu: Cleanup on ring failure

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/amdgpu: fence array leak in amdgpu_fence_driver_fini_ring() - [Medium] drm/amdgpu: invalid WB…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/amdgpu: fence array leak in amdgpu_fence_driver_fini_ring()
- [Medium] drm/amdgpu: invalid WB slot 0 free on fence init error in amdgpu_ring_init()
--

commit 3860c6ba520690a3a97d15071c514291b18c54d5
Author: Tvrtko Ursulin <[email protected]>

drm/amdgpu: Cleanup on ring failure

This commit exports amdgpu_fence_driver_fini_ring(), marks unallocated writeback slots as AMDGPU_RING_WB_INVALID, and calls amdgpu_ring_fini() on failure in amdgpu_ring_init().

Quoted 49 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +20 -17
index d0a6901532fd6..141bf5503755f 100644
@@ -577,31 +577,43 @@ void amdgpu_fence_driver_isr_toggle(struct amdgpu_device *adev, bool stop)
 	}
 }
 
-void amdgpu_fence_driver_sw_fini(struct amdgpu_device *adev)
+/**
+ * amdgpu_fence_driver_fini_ring - fini the fence driver
+ * for the requested ring.
+ *
+ * @ring: ring to fini the fence driver on
+ *
+ * Cleanup the fence driver for the requested ring (all asics).
+ */
+void amdgpu_fence_driver_fini_ring(struct amdgpu_ring *ring)
 {
-	unsigned int i, j;
+	unsigned int i;
 
-	for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
-		struct amdgpu_ring *ring = adev->rings[i];
+	if (!ring || !ring->fence_drv.initialized)
+		return;
 
-		if (!ring || !ring->fence_drv.initialized)
-			continue;
+	/*
+	 * Notice we check for sched.ops since there's some
+	 * override on the meaning of sched.ready by amdgpu.
+	 * The natural check would be sched.ready, which is
+	 * set as drm_sched_init() finishes...
+	 */
+	if (ring->sched.ops)
+		drm_sched_fini(&ring->sched);
 
-		/*
-		 * Notice we check for sched.ops since there's some
-		 * override on the meaning of sched.ready by amdgpu.
-		 * The natural check would be sched.ready, which is
-		 * set as drm_sched_init() finishes...
-		 */
-		if (ring->sched.ops)
-			drm_sched_fini(&ring->sched);
-
-		for (j = 0; j <= ring->fence_drv.num_fences_mask; ++j)
-			dma_fence_put(ring->fence_drv.fences[j]);

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c void amdgpu_fence_driver_isr_toggle(struct amdgpu_device *adev, bool stop) · line 609

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +6 -4
-		kfree(ring->fence_drv.fences);
-		ring->fence_drv.fences = NULL;
-		ring->fence_drv.initialized = false;
-	}
+	for (i = 0; i <= ring->fence_drv.num_fences_mask; ++i)
+		dma_fence_put(ring->fence_drv.fences[i]);
+	kfree(ring->fence_drv.fences);
+	ring->fence_drv.fences = NULL;
+	ring->fence_drv.initialized = false;
+}

[Severity: Medium]
Does checking ring->fence_drv.initialized here leak ring->fence_drv.fences?

amdgpu_fence_driver_init_ring() allocates ring->fence_drv.fences with ring->fence_drv.initialized set to false, and initialized is only set to true later by amdgpu_fence_driver_start_ring() (which is never called for AMDGPU_RING_TYPE_CPER rings). If any of the five amdgpu_wb_get() calls in amdgpu_ring_init() fails, or when a CPER ring is torn down, amdgpu_fence_driver_fini_ring() returns early without freeing ring->fence_drv.fences, and amdgpu_ring_fini() then clears ring->adev->rings[ring->idx] and ring->adev.

[ ... ]

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, · line 253

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +5 -0
index 71cabb884ac20..2a2b4c39c2892 100644
@@ -246,34 +246,40 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 			return r;
 	}
 
+	ring->rptr_offs = AMDGPU_RING_WB_INVALID;
+	ring->wptr_offs = AMDGPU_RING_WB_INVALID;
+	ring->fence_offs = AMDGPU_RING_WB_INVALID;
+	ring->trail_fence_offs = AMDGPU_RING_WB_INVALID;
+	ring->cond_exe_offs = AMDGPU_RING_WB_INVALID;

[Severity: Medium]
Can an error return from amdgpu_fence_driver_init_ring() right above this cause amdgpu_ring_fini() to free writeback slot 0 five times?

Before calling amdgpu_fence_driver_init_ring(), amdgpu_ring_init() has already set ring->adev and adev->rings[ring->idx]:

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c:amdgpu_ring_init() {
	if (ring->adev == NULL) {
		if (adev->num_rings >= AMDGPU_MAX_RINGS)
			return -EINVAL;

		ring->adev = adev;
		...
		ring->idx = adev->num_rings++;
		adev->rings[ring->idx] = ring;

		r = amdgpu_fence_driver_init_ring(ring);
		if (r)
			return r;
	}
}

If amdgpu_fence_driver_init_ring() fails, the five writeback offsets are left at 0 rather than AMDGPU_RING_WB_INVALID, so a subsequent amdgpu_ring_fini() during teardown (for example via amdgpu_cper_fini()) passes the ring->adev and adev->rings[ring->idx] check and calls amdgpu_wb_free(ring->adev, 0) for each of the five offsets.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#4 lore raw

RFC v2 3/4 drm/amdgpu: Unconfuse amdgpu_ring_init()

In reply to Tvrtko Ursulin

Ever since amdgpu was first added in commit
d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)") amdgpu_ring_init() was doing a subset of initialization steps based on the ring->adev being NULL or not.

I am not sure what was the situation back then, but certainly in todays code base I cannot see that any caller sets ring->adev to something before calling amdgpu_ring_init(). Furthermore, I do not see how that would be safe and sensible because it would leak objects which were already initialized.

Lets just remove this special case and as a bonus only "publish" the ring to global struct amdgpu_device once it has been successfully constructed.

References: d38ceaf99ed0 ("drm/amdgpu: add core driver (v4)")
Cc: Alex Deucher <[email protected]>
Cc: Christian König <[email protected]>
Cc: Alex Deucher <[email protected]>
Cc: Timur Kristóf <[email protected]>

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 30 ++++++++++--------------
 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +13 -17
index 2a2b4c39c289..f82352078646 100644
@@ -217,6 +217,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 	unsigned int max_ibs_dw;
 	int r;
 
+	if (adev->num_rings >= AMDGPU_MAX_RINGS)
+		return -EINVAL;
+
 	/* Set the hw submission limit higher for KIQ because
 	 * it's used for a number of gfx/compute tasks by both
 	 * KFD and KGD which may have outstanding fences and
@@ -230,21 +233,13 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 	else if (ring == &adev->sdma.instance[0].page)
 		sched_hw_submission = 256;
 
-	if (ring->adev == NULL) {
-		if (adev->num_rings >= AMDGPU_MAX_RINGS)
-			return -EINVAL;
+	ring->adev = adev;
+	ring->num_hw_submission = sched_hw_submission;
+	ring->sched_score = sched_score;
 
-		ring->adev = adev;
-		ring->num_hw_submission = sched_hw_submission;
-		ring->sched_score = sched_score;
-
-		ring->idx = adev->num_rings++;
-		adev->rings[ring->idx] = ring;
-
-		r = amdgpu_fence_driver_init_ring(ring);
-		if (r)
-			return r;
-	}
+	r = amdgpu_fence_driver_init_ring(ring);
+	if (r)
+		return r;
 
 	ring->rptr_offs = AMDGPU_RING_WB_INVALID;
 	ring->wptr_offs = AMDGPU_RING_WB_INVALID;
@@ -369,6 +364,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 		gpu_sched->sched[gpu_sched->num_scheds++] = &ring->sched;
 	}
 
+	ring->idx = adev->num_rings++;
+	adev->rings[ring->idx] = ring;
+
 	return 0;
 
 err:
@@ -386,8 +384,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 void amdgpu_ring_fini(struct amdgpu_ring *ring)
 {
 
-	/* Not to finish a ring which is not initialized */
-	if (!(ring->adev) || !(ring->adev->rings[ring->idx]))
+	if (!ring->adev)
 		return;
 
 	ring->sched.ready = false;
@@ -417,7 +414,6 @@ void amdgpu_ring_fini(struct amdgpu_ring *ring)
 	dma_fence_put(ring->vmid_wait);
 	ring->vmid_wait = NULL;
 	ring->me = 0;
-	ring->adev->rings[ring->idx] = NULL;
 	ring->adev = NULL;
 }
 
Signature · 1 line
2.56.0
#5 lore raw

Re: [RFC v2 3/4] drm/amdgpu: Unconfuse amdgpu_ring_init()

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/amdgpu: invalid writeback slot 0 free after amdgpu_ring_init() failure --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/amdgpu: invalid writeback slot 0 free after amdgpu_ring_init() failure
--

commit 2f4b28cebbd5fafa9eaae6b7dedcf51f49d518ac
Author: Tvrtko Ursulin <[email protected]>

drm/amdgpu: Unconfuse amdgpu_ring_init()

This commit removes the ring->adev == NULL check in amdgpu_ring_init() and defers registering the ring in adev->rings[] until initialization succeeds.

Quoted 42 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +9 -14
index 2a2b4c39c2892..f82352078646b 100644
@@ -217,6 +217,9 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 	unsigned int max_ibs_dw;
 	int r;
 
+	if (adev->num_rings >= AMDGPU_MAX_RINGS)
+		return -EINVAL;
+
 	/* Set the hw submission limit higher for KIQ because
 	 * it's used for a number of gfx/compute tasks by both
 	 * KFD and KGD which may have outstanding fences and
@@ -230,21 +233,13 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 	else if (ring == &adev->sdma.instance[0].page)
 		sched_hw_submission = 256;
 
-	if (ring->adev == NULL) {
-		if (adev->num_rings >= AMDGPU_MAX_RINGS)
-			return -EINVAL;
-
-		ring->adev = adev;
-		ring->num_hw_submission = sched_hw_submission;
-		ring->sched_score = sched_score;
-
-		ring->idx = adev->num_rings++;
-		adev->rings[ring->idx] = ring;
+	ring->adev = adev;
+	ring->num_hw_submission = sched_hw_submission;
+	ring->sched_score = sched_score;
 
-		r = amdgpu_fence_driver_init_ring(ring);
-		if (r)
-			return r;
-	}
+	r = amdgpu_fence_driver_init_ring(ring);
+	if (r)
+		return r;
 
 	ring->rptr_offs = AMDGPU_RING_WB_INVALID;
 	ring->wptr_offs = AMDGPU_RING_WB_INVALID;

[ ... ]

drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring, · line 388

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +1 -2
@@ -386,8 +384,7 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 void amdgpu_ring_fini(struct amdgpu_ring *ring)
 {
 
-	/* Not to finish a ring which is not initialized */
-	if (!(ring->adev) || !(ring->adev->rings[ring->idx]))
+	if (!ring->adev)
 		return;

[Severity: Medium]
Can this free writeback slot 0 belonging to another ring when amdgpu_fence_driver_init_ring() fails?

If amdgpu_fence_driver_init_ring() returns an error, amdgpu_ring_init() returns early with ring->adev set and the five writeback offsets (rptr_offs, wptr_offs, fence_offs, trail_fence_offs, and cond_exe_offs) still zero-initialized rather than set to AMDGPU_RING_WB_INVALID. When teardown later calls amdgpu_ring_fini() (for example via amdgpu_device_ip_fini() -> amdgpu_cper_fini()), it now passes the !ring->adev check and calls amdgpu_wb_free(ring->adev, 0) for each offset.

Resetting ring->adev = NULL before returning on amdgpu_fence_driver_init_ring() failure would avoid this.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#6 lore raw

RFC v2 4/4 drm/amdgpu: Use high priority scheduler workqueue for high priority rings

In reply to Tvrtko Ursulin

Back when DRM scheduler was kthread based the submission threads were using SCHED_FIFO to minimize the delays in feeding the GPU. This was lost with the conversion to workqueues but has recently been shown on other drivers (panthor, xe) that modern userspace can still suffer severe submission latencies under CPU load.

Lets convert amdgpu to use own workqueues and make the high priority rings use WQ_HIGHPRI while at it.

This is not expected to be a significant latency improvement, but it paves the way to start using WQ_RT which is queued for 7.5. At that point we can switch to using it with a single line patch and bring submission latencies under CPU load back to what they were in the past.

References: a6149f039369 ("drm/sched: Convert drm scheduler to use a work queue rather than kthread")
References: https://gitlab.freedesktop.org/panfrost/linux/-/work_items/49
References: https://lore.kernel.org/dri-devel/[email protected]/
References: https://lore.kernel.org/dri-devel/[email protected]/
Cc: Alex Deucher <[email protected]>
Cc: Christian König <[email protected]>
Cc: Timur Kristóf <[email protected]>
---
v2:
* Free the workqueue if it has been allocated.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c  |  3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c   | 10 ++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h   |  1 +
 4 files changed, 15 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +1 -0
index d0b08d2daea2..7638e4230307 100644
@@ -2367,6 +2367,7 @@ static int amdgpu_device_init_schedulers(struct amdgpu_device *adev)
 		args.credit_limit = ring->num_hw_submission;
 		args.score = ring->sched_score;
 		args.name = ring->name;
+		args.submit_wq = ring->sched_wq;
 
 		r = drm_sched_init(&ring->sched, &args);
 		if (r) {
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +3 -0
index a16bda03a13a..c406b759db28 100644
@@ -601,6 +601,9 @@ void amdgpu_fence_driver_fini_ring(struct amdgpu_ring *ring)
 	if (ring->sched.ops)
 		drm_sched_fini(&ring->sched);
 
+	if (ring->sched_wq)
+		destroy_workqueue(ring->sched_wq);
+
 	for (i = 0; i <= ring->fence_drv.num_fences_mask; ++i)
 		dma_fence_put(ring->fence_drv.fences[i]);
 	kfree(ring->fence_drv.fences);
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c +10 -0
index f82352078646..69b5b1c47d03 100644
@@ -360,6 +360,16 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
 	if (!ring->no_scheduler && ring->funcs->type < AMDGPU_HW_IP_NUM) {
 		struct amdgpu_sched *gpu_sched =
 			&adev->gpu_sched[ring->funcs->type][hw_prio];
+		unsigned int flags = WQ_MEM_RECLAIM;
+
+		if (hw_prio > AMDGPU_RING_PRIO_DEFAULT)
+			flags |= WQ_HIGHPRI;
+
+		ring->sched_wq = alloc_ordered_workqueue(ring->name, flags);
+		if (!ring->sched_wq) {
+			r = -ENOMEM;
+			goto err;
+		}
 
 		gpu_sched->sched[gpu_sched->num_scheds++] = &ring->sched;
 	}
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -0
index 9e9565b0e286..6eed8e63d513 100644
@@ -309,6 +309,7 @@ struct amdgpu_ring {
 	struct amdgpu_fence_driver	fence_drv;
 	struct drm_gpu_scheduler	sched;
 
+	struct workqueue_struct	*sched_wq;
 	struct amdgpu_bo	*ring_obj;
 	uint32_t		*ring;
 	/* backups for resets */
Signature · 1 line
2.56.0