Skip to contentSkip to conversation

drm/amdkfd: enable SDMA indirect buffers

PATCH In review Yongqiang Sun 2 participants 2 messages Oct 16 – Oct 17

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

PATCH 1/1 drm/amdkfd: enable SDMA indirect buffers

SDMA MQDs leave IB_ENABLE clear,
causing INDIRECT packets to be ignored.

Set IB_ENABLE while retaining SWITCH_INSIDE_IB.

---
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c   | 10 ++++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c   | 10 ++++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c   |  7 ++++++-
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c | 14 +++++++++-----
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c    |  8 +++++++-
 5 files changed, 42 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +10 -0
index 4f8a8a1a6186..ee7076db300a 100644
@@ -396,6 +396,16 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 	m->sdma_queue_id = q->sdma_queue_id;
 	m->sdmax_rlcx_dummy_reg = SDMA_RLC_DUMMY_DEFAULT;
 
+	/*
+	 * IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	 * packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	 * of a long-running command, including one fetched from an IB, so
+	 * one queue cannot starve the engine.
+	 * sdmax_rlcx_ib_cntl is the SDMA_RLC0_IB_CNTL register.
+	 */
+	 m->sdmax_rlcx_ib_cntl |= SDMA0_RLC0_IB_CNTL__IB_ENABLE_MASK |
+	 SDMA0_RLC0_IB_CNTL__SWITCH_INSIDE_IB_MASK;
+
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }
 
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +10 -0
index bf015dc5b868..4ed00e2d7bf4 100644
@@ -478,6 +478,16 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 	m->sdma_queue_id = q->sdma_queue_id;
 	m->sdmax_rlcx_dummy_reg = SDMA_RLC_DUMMY_DEFAULT;
 
+	/*
+	 * IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	 * packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	 * of a long-running command, including one fetched from an IB, so
+	 * one queue cannot starve the engine.
+	 * sdmax_rlcx_ib_cntl is the SDMA_QUEUE0_IB_CNTL register.
+	 */
+	 m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK |
+	 SDMA0_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK;
+
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }
 
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c +6 -1
index 6ea09b031caf..3f2234edb1fe 100644
@@ -355,9 +355,14 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 
 	/* Allow context switch so we don't cross-process starve with a massive
 	* command buffer of long-running SDMA commands
+	* IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	* packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	* of a long-running command, including one fetched from an IB, so
+	* one queue cannot starve the engine.
 	* sdmax_rlcx_ib_cntl represent SDMA_QUEUE0_IB_CNTL register
 	*/
-	m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK;
+	m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK |
+					SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK;
 
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c +9 -5
index 2bbf5e63f615..e71467862436 100644
@@ -457,11 +457,15 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 
 	m->sdmax_queuen_dummy_reg1 = 1;
 
-	/* Allow context switch so we don't cross-process starve with a massive
-	* command buffer of long-running SDMA commands
-	* sdmax_queuen_ib_cntl represent SDMA_QUEUE0_IB_CNTL register
-	*/
-	m->sdmax_queuen_ib_cntl |= SDMA0_SDMA_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK;
+	/*
+	 * IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	 * packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	 * of a long-running command, including one fetched from an IB, so
+	 * one queue cannot starve the engine.
+	 * sdmax_queuen_ib_cntl is the SDMA_QUEUE0_IB_CNTL register.
+	 */
+	m->sdmax_queuen_ib_cntl |= SDMA0_SDMA_QUEUE0_IB_CNTL__IB_ENABLE_MASK |
+				 SDMA0_SDMA_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK;
 
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +7 -1
index 6e6bc1ec0b64..c21091745869 100644
@@ -571,8 +571,14 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 	m->sdmax_rlcx_dummy_reg = SDMA_RLC_DUMMY_DEFAULT;
 	/* Allow context switch so we don't cross-process starve with a massive
 	 * command buffer of long-running SDMA commands
+	 * IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	 * packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	 * of a long-running command, including one fetched from an IB, so
+	 * one queue cannot starve the engine.
+	 * sdmax_rlcx_ib_cntl is the SDMA_GFX_IB_CNTL register.
 	 */
-	m->sdmax_rlcx_ib_cntl |= SDMA0_GFX_IB_CNTL__SWITCH_INSIDE_IB_MASK;
+	m->sdmax_rlcx_ib_cntl |= SDMA0_GFX_IB_CNTL__SWITCH_INSIDE_IB_MASK |
+					SDMA0_GFX_IB_CNTL__IB_ENABLE_MASK;
 
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }
Signature · 1 line
2.43.0
#1 lore raw
Quoted 6 lines · Yongqiang Sun

SDMA MQDs leave IB_ENABLE clear,
causing INDIRECT packets to be ignored.

Set IB_ENABLE while retaining SWITCH_INSIDE_IB.

Please update the patch heading to: "drm/amdkfd: Enable SDMA IB processing"

Quoted 15 lines
---
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c   | 10 ++++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c   | 10 ++++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c   |  7 ++++++-
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c | 14 +++++++++-----
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c    |  8 +++++++-
 5 files changed, 42 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +0 -0
index 4f8a8a1a6186..ee7076db300a 100644
@@ -396,6 +396,16 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 	m->sdma_queue_id = q->sdma_queue_id;
 	m->sdmax_rlcx_dummy_reg = SDMA_RLC_DUMMY_DEFAULT;

drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c static void update_mqd_sdma(struct mqd_manager *mm, void *mqd, · line 407

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +9 -0
 
+	/*
+	 * IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	 * packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	 * of a long-running command, including one fetched from an IB, so
+	 * one queue cannot starve the engine.
+	 * sdmax_rlcx_ib_cntl is the SDMA_RLC0_IB_CNTL register.
+	 */
+	 m->sdmax_rlcx_ib_cntl |= SDMA0_RLC0_IB_CNTL__IB_ENABLE_MASK |
+	 SDMA0_RLC0_IB_CNTL__SWITCH_INSIDE_IB_MASK;

Please check indentation here.

Quoted 12 lines
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +1 -0
+
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }
 
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +0 -0
index bf015dc5b868..4ed00e2d7bf4 100644
@@ -478,6 +478,16 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 	m->sdma_queue_id = q->sdma_queue_id;
 	m->sdmax_rlcx_dummy_reg = SDMA_RLC_DUMMY_DEFAULT;
 

drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c static void update_mqd_sdma(struct mqd_manager *mm, void *mqd, · line 490

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +10 -0
+	/*
+	 * IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	 * packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	 * of a long-running command, including one fetched from an IB, so
+	 * one queue cannot starve the engine.
+	 * sdmax_rlcx_ib_cntl is the SDMA_QUEUE0_IB_CNTL register.
+	 */
+	 m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK |
+	 SDMA0_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK;
+

Same here, please check the indentation and make it consistent for all ASIC versions in the patch.

Quoted 33 lines
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +0 -0
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }
 
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12.c +6 -1
index 6ea09b031caf..3f2234edb1fe 100644
@@ -355,9 +355,14 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 
 	/* Allow context switch so we don't cross-process starve with a massive
 	* command buffer of long-running SDMA commands
+	* IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	* packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	* of a long-running command, including one fetched from an IB, so
+	* one queue cannot starve the engine.
 	* sdmax_rlcx_ib_cntl represent SDMA_QUEUE0_IB_CNTL register
 	*/
-	m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK;
+	m->sdmax_rlcx_ib_cntl |= SDMA0_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK |
+					SDMA0_QUEUE0_IB_CNTL__IB_ENABLE_MASK;
 
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c +0 -2
index 2bbf5e63f615..e71467862436 100644
@@ -457,11 +457,15 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 
 	m->sdmax_queuen_dummy_reg1 = 1;
 
-	/* Allow context switch so we don't cross-process starve with a massive
-	* command buffer of long-running SDMA commands

drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c static void update_mqd_sdma(struct mqd_manager *mm, void *mqd, · line 466

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c +7 -3
-	* sdmax_queuen_ib_cntl represent SDMA_QUEUE0_IB_CNTL register
-	*/
-	m->sdmax_queuen_ib_cntl |= SDMA0_SDMA_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK;
+	/*
+	 * IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	 * packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	 * of a long-running command, including one fetched from an IB, so
+	 * one queue cannot starve the engine.
+	 * sdmax_queuen_ib_cntl is the SDMA_QUEUE0_IB_CNTL register.
+	 */

Make the comment consistent across all versions.

Some have "Allow context switch...", some don't.

Maybe consider replacing it with less verbose message like:
/* Enable IB execution; allow context switch inside an IB so one queue can't starve the engine. */

Regards,

Mukul

Quoted 25 lines
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v12_1.c +2 -0
+	m->sdmax_queuen_ib_cntl |= SDMA0_SDMA_QUEUE0_IB_CNTL__IB_ENABLE_MASK |
+				 SDMA0_SDMA_QUEUE0_IB_CNTL__SWITCH_INSIDE_IB_MASK;
 
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +7 -1
index 6e6bc1ec0b64..c21091745869 100644
@@ -571,8 +571,14 @@ static void update_mqd_sdma(struct mqd_manager *mm, void *mqd,
 	m->sdmax_rlcx_dummy_reg = SDMA_RLC_DUMMY_DEFAULT;
 	/* Allow context switch so we don't cross-process starve with a massive
 	 * command buffer of long-running SDMA commands
+	 * IB_ENABLE makes this user queue execute SDMA indirect-buffer
+	 * packets. SWITCH_INSIDE_IB allows a context switch in the middle
+	 * of a long-running command, including one fetched from an IB, so
+	 * one queue cannot starve the engine.
+	 * sdmax_rlcx_ib_cntl is the SDMA_GFX_IB_CNTL register.
 	 */
-	m->sdmax_rlcx_ib_cntl |= SDMA0_GFX_IB_CNTL__SWITCH_INSIDE_IB_MASK;
+	m->sdmax_rlcx_ib_cntl |= SDMA0_GFX_IB_CNTL__SWITCH_INSIDE_IB_MASK |
+					SDMA0_GFX_IB_CNTL__IB_ENABLE_MASK;
 
 	q->is_active = QUEUE_IS_ACTIVE(*q);
 }