Skip to contentSkip to conversation

Avoid re-parser CSB in gfx_vX_0_cp_gfx_start()

PATCH In review Rodrigo Siqueira 2 participants 9 messages May 4, 2025 – May 5, 2025

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

cover Avoid re-parser CSB in gfx_vX_0_cp_gfx_start()

In the functions gfx_vX_0_cp_gfx_start(), where X ranges from 7 to 11, parts of the code parser CSB. However, CSB was already parsed in the get_csb_buffer() called before gfx_vX_0_cp_gfx_start(). This commit introduces a helper to read directly from the CSB buffer available in adev->gfx.rlc.cs_ptr, and avoid re-parse CSB.

Note: This series idea came from a discussion available in the below link:

https://lore.kernel.org/amd-gfx/CADnq5_NAGvaJ1-7+_NZQszLspHcCudRSKKHkezJBEQg0GmEq9Q@mail.gmail.com/T/#m8fd6d9ce10b9644299f2f306f2a7d00a9aa1e5ee

Thanks

Rodrigo Siqueira (6):
drm/amd/amdgpu: Add a helper to copy the CSB buffer into the ring
buffer
drm/amd/amdgpu: Avoid re-parser CSB in gfx_v7_0_cp_gfx_start drm/amd/amdgpu: Avoid re-parser CSB in gfx_v8_0_cp_gfx_start drm/amd/amdgpu: Avoid re-parser CSB in gfx_v9_0_cp_gfx_start drm/amd/amdgpu: Avoid re-parser CSB in gfx_v10_0_cp_gfx_start drm/amd/amdgpu: Avoid re-parser CSB in gfx_v11_0_cp_gfx_start

 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 21 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  4 ++++
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c  | 23 +++++------------------
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c  | 23 +++++------------------
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c   | 20 +++++---------------
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c   | 22 +++++-----------------
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c   | 23 ++++++-----------------
 7 files changed, 51 insertions(+), 85 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/6 drm/amd/amdgpu: Add a helper to copy the CSB buffer into the ring buffer

In the GFX code, there are multiple parsers of the CSB buffer, which can be avoided. This data is parsed via get_csb_buffer() in earlier stages, and the result can be checked in "adev->gfx.rlc.cs_ptr". To avoid re-parser the CSB buffer, this commit introduces a helper that copies the CSB buffer into the ring buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 21 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  4 ++++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +21 -0
index 8f1a2f7b03c1..dfd48670a0bf 100644
@@ -2323,6 +2323,27 @@ void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count)
 	buffer[count++] = cpu_to_le32(0);
 }
 
+/**
+ * amdgpu_gfx_write_csb_to_ring - Write the CSB buffer into the ring
+ *
+ * @ring: Ring reference.
+ * @csb_buffer: CSB buffer.
+ * @csb_size: CSB buffer size.
+ *
+ * Usually, the adev->gfx.rlc.cs_ptr field is filled in earlier stages via
+ * get_csb_buffer(). This function just gets the CSB buffer and fills it in the
+ * ring buffer.
+ */
+void amdgpu_gfx_write_csb_to_ring(struct amdgpu_ring *ring,
+				  volatile u32 *csb_buffer,
+				  u32 csb_size)
+{
+	int i;
+
+	for (i = 0; i < csb_size; i++)
+		amdgpu_ring_write(ring, csb_buffer[i]);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +4 -0
index 08f268dab8f5..ce684c3d3d89 100644
@@ -646,6 +646,10 @@ u32 amdgpu_gfx_csb_preamble_start(volatile u32 *buffer);
 u32 amdgpu_gfx_csb_data_parser(struct amdgpu_device *adev, volatile u32 *buffer, u32 count);
 void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count);
 
+void amdgpu_gfx_write_csb_to_ring(struct amdgpu_ring *ring,
+				  volatile u32 *csb_buffer,
+				  u32 csb_size);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
Signature · 1 line
2.47.2
maintainer
#2 lore raw

Re: [PATCH 1/6] drm/amd/amdgpu: Add a helper to copy the CSB buffer into the ring buffer

Quoted 22 lines · Rodrigo Siqueira

In the GFX code, there are multiple parsers of the CSB buffer, which can be avoided. This data is parsed via get_csb_buffer() in earlier stages, and the result can be checked in "adev->gfx.rlc.cs_ptr". To avoid re-parser the CSB buffer, this commit introduces a helper that copies the CSB buffer into the ring buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 21 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  4 ++++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +2 -0
index 8f1a2f7b03c1..dfd48670a0bf 100644
@@ -2323,6 +2323,27 @@ void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count)
 	buffer[count++] = cpu_to_le32(0);
 }
 
+/**
+ * amdgpu_gfx_write_csb_to_ring - Write the CSB buffer into the ring

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count) · line 2337

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +10 -0
+ *
+ * @ring: Ring reference.
+ * @csb_buffer: CSB buffer.
+ * @csb_size: CSB buffer size.
+ *
+ * Usually, the adev->gfx.rlc.cs_ptr field is filled in earlier stages via
+ * get_csb_buffer(). This function just gets the CSB buffer and fills it in the
+ * ring buffer.
+ */
+void amdgpu_gfx_write_csb_to_ring(struct amdgpu_ring *ring,

We already have the amdgpu_ring_write_multiple() function for exactly that.

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count) · line 2338

Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -0
+				  volatile u32 *csb_buffer,

Please drop volatile from all pointers inside the kernel and point me out if you still find some in existing code.

They are nearly always used incorrectly, see here https://docs.kernel.org/process/volatile-considered-harmful.html

Thanks,
Christian.

Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -0
+				  u32 csb_size)
 
 
 
 
+{
+	int i;
+
+	for (i = 0; i < csb_size; i++)
+		amdgpu_ring_write(ring, csb_buffer[i]);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +4 -0
index 08f268dab8f5..ce684c3d3d89 100644
@@ -646,6 +646,10 @@ u32 amdgpu_gfx_csb_preamble_start(volatile u32 *buffer);
 u32 amdgpu_gfx_csb_data_parser(struct amdgpu_device *adev, volatile u32 *buffer, u32 count);
 void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count);
 
+void amdgpu_gfx_write_csb_to_ring(struct amdgpu_ring *ring,
+				  volatile u32 *csb_buffer,
+				  u32 csb_size);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
#3 lore raw

Re: [PATCH 1/6] drm/amd/amdgpu: Add a helper to copy the CSB buffer into the ring buffer

Quoted 21 lines · Christian König
Quoted 20 lines · Rodrigo Siqueira

In the GFX code, there are multiple parsers of the CSB buffer, which can be avoided. This data is parsed via get_csb_buffer() in earlier stages, and the result can be checked in "adev->gfx.rlc.cs_ptr". To avoid re-parser the CSB buffer, this commit introduces a helper that copies the CSB buffer into the ring buffer.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 21 +++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h |  4 ++++
 2 files changed, 25 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +0 -0
index 8f1a2f7b03c1..dfd48670a0bf 100644
@@ -2323,6 +2323,27 @@ void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count)
 	buffer[count++] = cpu_to_le32(0);
 }
 
Quoted 14 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count) · line 2337

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +12 -0
+/**
+ * amdgpu_gfx_write_csb_to_ring - Write the CSB buffer into the ring
+ *
+ * @ring: Ring reference.
+ * @csb_buffer: CSB buffer.
+ * @csb_size: CSB buffer size.
+ *
+ * Usually, the adev->gfx.rlc.cs_ptr field is filled in earlier stages via
+ * get_csb_buffer(). This function just gets the CSB buffer and fills it in the
+ * ring buffer.
+ */
+void amdgpu_gfx_write_csb_to_ring(struct amdgpu_ring *ring,

We already have the amdgpu_ring_write_multiple() function for exactly that.

I'll prepare a V2 that uses amdgpu_ring_write_multiple().

Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count) · line 2338

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +1 -0
+				  volatile u32 *csb_buffer,

Please drop volatile from all pointers inside the kernel and point me out if you still find some in existing code.

They are nearly always used incorrectly, see here https://docs.kernel.org/process/volatile-considered-harmful.html

Thanks for the link. I'll make a separate patchset for that.

Thanks
Siqueira

Quoted 36 lines

Thanks,
Christian.

Quoted 30 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c +8 -0
+				  u32 csb_size)
 
 
 
 
+{
+	int i;
+
+	for (i = 0; i < csb_size; i++)
+		amdgpu_ring_write(ring, csb_buffer[i]);
+}
+
 /*
  * debugfs for to enable/disable gfx job submission to specific core.
  */
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +4 -0
index 08f268dab8f5..ce684c3d3d89 100644
@@ -646,6 +646,10 @@ u32 amdgpu_gfx_csb_preamble_start(volatile u32 *buffer);
 u32 amdgpu_gfx_csb_data_parser(struct amdgpu_device *adev, volatile u32 *buffer, u32 count);
 void amdgpu_gfx_csb_preamble_end(volatile u32 *buffer, u32 count);
 
+void amdgpu_gfx_write_csb_to_ring(struct amdgpu_ring *ring,
+				  volatile u32 *csb_buffer,
+				  u32 csb_size);
+
 void amdgpu_debugfs_gfx_sched_mask_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_compute_sched_mask_init(struct amdgpu_device *adev);
 
Signature · 1 line
Rodrigo Siqueira
#4 lore raw

PATCH 2/6 drm/amd/amdgpu: Avoid re-parser CSB in gfx_v7_0_cp_gfx_start

In reply to Rodrigo Siqueira

Remove the unnecessary parser of the CSB buffer in the GFX7, and directly use the result from "adev->gfx.rlc.cs_ptr".

---
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c | 20 +++++---------------
 1 file changed, 5 insertions(+), 15 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +5 -15
index da0534ff1271..35938090fbae 100644
@@ -2460,9 +2460,8 @@ static int gfx_v7_0_cp_gfx_load_microcode(struct amdgpu_device *adev)
 static int gfx_v7_0_cp_gfx_start(struct amdgpu_device *adev)
 {
 	struct amdgpu_ring *ring = &adev->gfx.gfx_ring[0];
-	const struct cs_section_def *sect = NULL;
-	const struct cs_extent_def *ext = NULL;
-	int r, i;
+	u32 csb_size;
+	int r;
 
 	/* init the CP */
 	WREG32(mmCP_MAX_CONTEXT, adev->gfx.config.max_hw_contexts - 1);
@@ -2471,7 +2470,8 @@ static int gfx_v7_0_cp_gfx_start(struct amdgpu_device *adev)
 
 	gfx_v7_0_cp_gfx_enable(adev, true);
 
-	r = amdgpu_ring_alloc(ring, gfx_v7_0_get_csb_size(adev) + 8);
+	csb_size = gfx_v7_0_get_csb_size(adev);
+	r = amdgpu_ring_alloc(ring, csb_size + 8);
 	if (r) {
 		DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
 		return r;
@@ -2491,17 +2491,7 @@ static int gfx_v7_0_cp_gfx_start(struct amdgpu_device *adev)
 	amdgpu_ring_write(ring, 0x80000000);
 	amdgpu_ring_write(ring, 0x80000000);
 
-	for (sect = adev->gfx.rlc.cs_data; sect->section != NULL; ++sect) {
-		for (ext = sect->section; ext->extent != NULL; ++ext) {
-			if (sect->id == SECT_CONTEXT) {
-				amdgpu_ring_write(ring,
-						  PACKET3(PACKET3_SET_CONTEXT_REG, ext->reg_count));
-				amdgpu_ring_write(ring, ext->reg_index - PACKET3_SET_CONTEXT_REG_START);
-				for (i = 0; i < ext->reg_count; i++)
-					amdgpu_ring_write(ring, ext->extent[i]);
-			}
-		}
-	}
+	amdgpu_gfx_write_csb_to_ring(ring, adev->gfx.rlc.cs_ptr, csb_size);
 
 	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
 	amdgpu_ring_write(ring, mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
Signature · 1 line
2.47.2
#5 lore raw

PATCH 3/6 drm/amd/amdgpu: Avoid re-parser CSB in gfx_v8_0_cp_gfx_start

In reply to Rodrigo Siqueira

Remove the unnecessary parser of the CSB buffer in the GFX8, and directly use the result from "adev->gfx.rlc.cs_ptr".

---
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c | 22 +++++-----------------
 1 file changed, 5 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +5 -17
index 5ee2237d8ee8..bdd09d77713c 100644
@@ -4126,9 +4126,8 @@ static u32 gfx_v8_0_get_csb_size(struct amdgpu_device *adev)
 static int gfx_v8_0_cp_gfx_start(struct amdgpu_device *adev)
 {
 	struct amdgpu_ring *ring = &adev->gfx.gfx_ring[0];
-	const struct cs_section_def *sect = NULL;
-	const struct cs_extent_def *ext = NULL;
-	int r, i;
+	u32 csb_size;
+	int r;
 
 	/* init the CP */
 	WREG32(mmCP_MAX_CONTEXT, adev->gfx.config.max_hw_contexts - 1);
@@ -4137,7 +4136,8 @@ static int gfx_v8_0_cp_gfx_start(struct amdgpu_device *adev)
 
 	gfx_v8_0_cp_gfx_enable(adev, true);
 
-	r = amdgpu_ring_alloc(ring, gfx_v8_0_get_csb_size(adev) + 4);
+	csb_size = gfx_v8_0_get_csb_size(adev);
+	r = amdgpu_ring_alloc(ring, csb_size + 4);
 	if (r) {
 		DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
 		return r;
@@ -4151,19 +4151,7 @@ static int gfx_v8_0_cp_gfx_start(struct amdgpu_device *adev)
 	amdgpu_ring_write(ring, 0x80000000);
 	amdgpu_ring_write(ring, 0x80000000);
 
-	for (sect = vi_cs_data; sect->section != NULL; ++sect) {
-		for (ext = sect->section; ext->extent != NULL; ++ext) {
-			if (sect->id == SECT_CONTEXT) {
-				amdgpu_ring_write(ring,
-				       PACKET3(PACKET3_SET_CONTEXT_REG,
-					       ext->reg_count));
-				amdgpu_ring_write(ring,
-				       ext->reg_index - PACKET3_SET_CONTEXT_REG_START);
-				for (i = 0; i < ext->reg_count; i++)
-					amdgpu_ring_write(ring, ext->extent[i]);
-			}
-		}
-	}
+	amdgpu_gfx_write_csb_to_ring(ring, adev->gfx.rlc.cs_ptr, csb_size);
 
 	amdgpu_ring_write(ring, PACKET3(PACKET3_SET_CONTEXT_REG, 2));
 	amdgpu_ring_write(ring, mmPA_SC_RASTER_CONFIG - PACKET3_SET_CONTEXT_REG_START);
Signature · 1 line
2.47.2
#6 lore raw

PATCH 4/6 drm/amd/amdgpu: Avoid re-parser CSB in gfx_v9_0_cp_gfx_start

In reply to Rodrigo Siqueira

Use amdgpu_gfx_write_csb_to_ring() to replace duplicated CSB parse in gfx_v9_0_cp_gfx_start().

---
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c | 23 ++++++-----------------
 1 file changed, 6 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +6 -17
index d377a7c57d5e..be38650a2b9b 100644
@@ -3295,9 +3295,8 @@ static int gfx_v9_0_cp_gfx_load_microcode(struct amdgpu_device *adev)
 static int gfx_v9_0_cp_gfx_start(struct amdgpu_device *adev)
 {
 	struct amdgpu_ring *ring = &adev->gfx.gfx_ring[0];
-	const struct cs_section_def *sect = NULL;
-	const struct cs_extent_def *ext = NULL;
-	int r, i, tmp;
+	u32 csb_size;
+	int r, tmp;
 
 	/* init the CP */
 	WREG32_SOC15(GC, 0, mmCP_MAX_CONTEXT, adev->gfx.config.max_hw_contexts - 1);
@@ -3313,7 +3312,9 @@ static int gfx_v9_0_cp_gfx_start(struct amdgpu_device *adev)
 		DRM_INFO("Will skip the CSB packet resubmit\n");
 		return 0;
 	}
-	r = amdgpu_ring_alloc(ring, gfx_v9_0_get_csb_size(adev) + 4 + 3);
+
+	csb_size = gfx_v9_0_get_csb_size(adev);
+	r = amdgpu_ring_alloc(ring, csb_size + 4 + 3);
 	if (r) {
 		DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
 		return r;
@@ -3326,19 +3327,7 @@ static int gfx_v9_0_cp_gfx_start(struct amdgpu_device *adev)
 	amdgpu_ring_write(ring, 0x80000000);
 	amdgpu_ring_write(ring, 0x80000000);
 
-	for (sect = gfx9_cs_data; sect->section != NULL; ++sect) {
-		for (ext = sect->section; ext->extent != NULL; ++ext) {
-			if (sect->id == SECT_CONTEXT) {
-				amdgpu_ring_write(ring,
-				       PACKET3(PACKET3_SET_CONTEXT_REG,
-					       ext->reg_count));
-				amdgpu_ring_write(ring,
-				       ext->reg_index - PACKET3_SET_CONTEXT_REG_START);
-				for (i = 0; i < ext->reg_count; i++)
-					amdgpu_ring_write(ring, ext->extent[i]);
-			}
-		}
-	}
+	amdgpu_gfx_write_csb_to_ring(ring, adev->gfx.rlc.cs_ptr, csb_size);
 
 	amdgpu_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
 	amdgpu_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
Signature · 1 line
2.47.2
#7 lore raw

PATCH 5/6 drm/amd/amdgpu: Avoid re-parser CSB in gfx_v10_0_cp_gfx_start

In reply to Rodrigo Siqueira

Remove the unnecessary parser of the CSB buffer, and directly use the result from "adev->gfx.rlc.cs_ptr".

---
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +5 -18
index 75ea071744eb..36ccb50c274b 100644
@@ -6359,10 +6359,8 @@ static int gfx_v10_0_cp_gfx_load_microcode(struct amdgpu_device *adev)
 static int gfx_v10_0_cp_gfx_start(struct amdgpu_device *adev)
 {
 	struct amdgpu_ring *ring;
-	const struct cs_section_def *sect = NULL;
-	const struct cs_extent_def *ext = NULL;
-	int r, i;
-	int ctx_reg_offset;
+	u32 csb_size;
+	int r, ctx_reg_offset;
 
 	/* init the CP */
 	WREG32_SOC15(GC, 0, mmCP_MAX_CONTEXT,
@@ -6371,8 +6369,9 @@ static int gfx_v10_0_cp_gfx_start(struct amdgpu_device *adev)
 
 	gfx_v10_0_cp_gfx_enable(adev, true);
 
+	csb_size = gfx_v10_0_get_csb_size(adev);
 	ring = &adev->gfx.gfx_ring[0];
-	r = amdgpu_ring_alloc(ring, gfx_v10_0_get_csb_size(adev) + 4);
+	r = amdgpu_ring_alloc(ring, csb_size + 4);
 	if (r) {
 		DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
 		return r;
@@ -6385,19 +6384,7 @@ static int gfx_v10_0_cp_gfx_start(struct amdgpu_device *adev)
 	amdgpu_ring_write(ring, 0x80000000);
 	amdgpu_ring_write(ring, 0x80000000);
 
-	for (sect = gfx10_cs_data; sect->section != NULL; ++sect) {
-		for (ext = sect->section; ext->extent != NULL; ++ext) {
-			if (sect->id == SECT_CONTEXT) {
-				amdgpu_ring_write(ring,
-						  PACKET3(PACKET3_SET_CONTEXT_REG,
-							  ext->reg_count));
-				amdgpu_ring_write(ring, ext->reg_index -
-						  PACKET3_SET_CONTEXT_REG_START);
-				for (i = 0; i < ext->reg_count; i++)
-					amdgpu_ring_write(ring, ext->extent[i]);
-			}
-		}
-	}
+	amdgpu_gfx_write_csb_to_ring(ring, adev->gfx.rlc.cs_ptr, csb_size);
 
 	ctx_reg_offset =
 		SOC15_REG_OFFSET(GC, 0, mmPA_SC_TILE_STEERING_OVERRIDE) - PACKET3_SET_CONTEXT_REG_START;
Signature · 1 line
2.47.2
#8 lore raw

PATCH 6/6 drm/amd/amdgpu: Avoid re-parser CSB in gfx_v11_0_cp_gfx_start

In reply to Rodrigo Siqueira

Remove the unnecessary parser of the CSB buffer in the GFX11, and directly use the result from "adev->gfx.rlc.cs_ptr".

---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +5 -18
index 3f4ee4b3b0a4..a9ff66525ce1 100644
@@ -3575,10 +3575,8 @@ static int gfx_v11_0_cp_gfx_load_microcode(struct amdgpu_device *adev)
 static int gfx_v11_0_cp_gfx_start(struct amdgpu_device *adev)
 {
 	struct amdgpu_ring *ring;
-	const struct cs_section_def *sect = NULL;
-	const struct cs_extent_def *ext = NULL;
-	int r, i;
-	int ctx_reg_offset;
+	u32 csb_size;
+	int r, ctx_reg_offset;
 
 	/* init the CP */
 	WREG32_SOC15(GC, 0, regCP_MAX_CONTEXT,
@@ -3589,7 +3587,8 @@ static int gfx_v11_0_cp_gfx_start(struct amdgpu_device *adev)
 		gfx_v11_0_cp_gfx_enable(adev, true);
 
 	ring = &adev->gfx.gfx_ring[0];
-	r = amdgpu_ring_alloc(ring, gfx_v11_0_get_csb_size(adev));
+	csb_size = gfx_v11_0_get_csb_size(adev);
+	r = amdgpu_ring_alloc(ring, csb_size);
 	if (r) {
 		DRM_ERROR("amdgpu: cp failed to lock ring (%d).\n", r);
 		return r;
@@ -3602,19 +3601,7 @@ static int gfx_v11_0_cp_gfx_start(struct amdgpu_device *adev)
 	amdgpu_ring_write(ring, 0x80000000);
 	amdgpu_ring_write(ring, 0x80000000);
 
-	for (sect = gfx11_cs_data; sect->section != NULL; ++sect) {
-		for (ext = sect->section; ext->extent != NULL; ++ext) {
-			if (sect->id == SECT_CONTEXT) {
-				amdgpu_ring_write(ring,
-						  PACKET3(PACKET3_SET_CONTEXT_REG,
-							  ext->reg_count));
-				amdgpu_ring_write(ring, ext->reg_index -
-						  PACKET3_SET_CONTEXT_REG_START);
-				for (i = 0; i < ext->reg_count; i++)
-					amdgpu_ring_write(ring, ext->extent[i]);
-			}
-		}
-	}
+	amdgpu_gfx_write_csb_to_ring(ring, adev->gfx.rlc.cs_ptr, csb_size);
 
 	ctx_reg_offset =
 		SOC15_REG_OFFSET(GC, 0, regPA_SC_TILE_STEERING_OVERRIDE) - PACKET3_SET_CONTEXT_REG_START;
Signature · 1 line
2.47.2