Skip to contentSkip to conversation

drm/amd/amdgpu: Increase max rings to enable SDMA page ring

PATCH Superseded [email protected] 2 participants 3 messages Feb 19, 2025

Subsystems (2)

v2 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 drm/amd/amdgpu: Increase max rings to enable SDMA page ring

From: "[email protected]" <[email protected]>

Increase the maximum number of rings supported by the AMDGPU driver from 132 to 148. This change is necessary to enable support for the SDMA page ring.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h +1 -1
index 182aa535d395..ae1dd7d16048 100644
@@ -37,7 +37,7 @@ struct amdgpu_job;
 struct amdgpu_vm;
 
 /* max number of rings */
-#define AMDGPU_MAX_RINGS		132
+#define AMDGPU_MAX_RINGS		148
 #define AMDGPU_MAX_HWIP_RINGS		64
 #define AMDGPU_MAX_GFX_RINGS		2
 #define AMDGPU_MAX_SW_GFX_RINGS         2
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 2/2 drm/amdgpu: Optimize VM invalidation engine allocation and synchronize GPU TLB flush

From: "[email protected]" <[email protected]>

- Modify the VM invalidation engine allocation logic to handle SDMA page rings. SDMA page rings now share the VM invalidation engine with SDMA gfx rings instead of allocating a separate engine. This change ensures efficient resource management and avoids the issue of insufficient VM invalidation engines.

- Add synchronization for GPU TLB flush operations in gmc_v9_0.c.
Use spin_lock and spin_unlock to ensure thread safety and prevent race conditions during TLB flush operations. This improves the stability and reliability of the driver, especially in multi-threaded environments.

replace the sdma ring check with a function amdgpu_sdma_is_page_queue to check if a ring is an SDMA page queue.(Lijo)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c  |  7 +++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 18 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    |  2 ++
 4 files changed, 28 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +7 -0
index cb914ce82eb5..da719ec6c6c7 100644
@@ -601,8 +601,15 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)
 			return -EINVAL;
 		}
 
+	if(amdgpu_sdma_is_page_queue(adev, ring)) {
+		/* Do not allocate a separate VM invalidation engine for SDMA page rings.
+		 * Shared VM invalid engine with sdma gfx ring.
+		 */
+		ring->vm_inv_eng = inv_eng - 1;
+	} else {
 		ring->vm_inv_eng = inv_eng - 1;
 		vm_inv_engs[vmhub] &= ~(1 << ring->vm_inv_eng);
+	}
 
 		dev_info(adev->dev, "ring %s uses VM inv eng %u on hub %u\n",
 			 ring->name, ring->vm_inv_eng, ring->vm_hub);
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +18 -0
index 8de214a8ba6d..96df544feb67 100644
@@ -503,6 +503,24 @@ void amdgpu_sdma_sysfs_reset_mask_fini(struct amdgpu_device *adev)
 	}
 }
 
+/**
+* amdgpu_sdma_is_page_queue - Check if a ring is an SDMA page queue
+* @adev: Pointer to the AMDGPU device structure
+* @ring: Pointer to the ring structure to check
+*
+* This function checks if the given ring is an SDMA page queue.
+* It returns true if the ring is an SDMA page queue, false otherwise.
+*/
+bool amdgpu_sdma_is_page_queue(struct amdgpu_device *adev, struct amdgpu_ring* ring)
+{
+	int i = ring->me;
+
+	if (!adev->sdma.has_page_queue || i >= adev->sdma.num_instances)
+		return false;
+
+	return (ring == &adev->sdma.instance[i].page);
+}
+
 /**
  * amdgpu_sdma_register_on_reset_callbacks - Register SDMA reset callbacks
  * @funcs: Pointer to the callback structure containing pre_reset and post_reset functions
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1 -0
index 7effc2673466..c2df9c3ab882 100644
@@ -194,4 +194,5 @@ int amdgpu_sdma_ras_sw_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_sdma_sched_mask_init(struct amdgpu_device *adev);
 int amdgpu_sdma_sysfs_reset_mask_init(struct amdgpu_device *adev);
 void amdgpu_sdma_sysfs_reset_mask_fini(struct amdgpu_device *adev);
+bool amdgpu_sdma_is_page_queue(struct amdgpu_device *adev, struct amdgpu_ring* ring);
 #endif
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -0
index 2aa87fdf715f..2599da8677da 100644
@@ -1000,6 +1000,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
 	 * to WA the Issue
 	 */
 
+	spin_lock(&adev->gmc.invalidate_lock);
 	/* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
 	if (use_semaphore)
 		/* a read return value of 1 means semaphore acuqire */
@@ -1030,6 +1031,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
 		amdgpu_ring_emit_wreg(ring, hub->vm_inv_eng0_sem +
 				      hub->eng_distance * eng, 0);
 
+	spin_unlock(&adev->gmc.invalidate_lock);
 	return pd_addr;
 }
 
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH V2 2/2] drm/amdgpu: Optimize VM invalidation engine allocation and synchronize GPU TLB flush

Quoted 29 lines · On 2/19/2025 1:30 PM, [email protected] wrote:

From: "[email protected]" <[email protected]>

- Modify the VM invalidation engine allocation logic to handle SDMA page rings. SDMA page rings now share the VM invalidation engine with SDMA gfx rings instead of allocating a separate engine. This change ensures efficient resource management and avoids the issue of insufficient VM invalidation engines.

- Add synchronization for GPU TLB flush operations in gmc_v9_0.c.
Use spin_lock and spin_unlock to ensure thread safety and prevent race conditions during TLB flush operations. This improves the stability and reliability of the driver, especially in multi-threaded environments.

replace the sdma ring check with a function amdgpu_sdma_is_page_queue to check if a ring is an SDMA page queue.(Lijo)

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c  |  7 +++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c | 18 ++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h |  1 +
 drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c    |  2 ++
 4 files changed, 28 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -0
index cb914ce82eb5..da719ec6c6c7 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev) · line 604

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -0
@@ -601,8 +601,15 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)
 			return -EINVAL;
 		}
 
+	if(amdgpu_sdma_is_page_queue(adev, ring)) {

Sorry, didn't mean to exclude the ring type check.

BTW, there is another problem. If the previous ring is regular sdma ring,

vm_inv_engs[vmhub] &= ~(1 << ring->vm_inv_eng);

This step would have modified the bitmap and invalidation engine in the next loop is not the same.

What you may want to do is -

After allocating sdma ring invalidation engine, assign the same inv engine to page ring corresponding to the sdma instance.

	ring->vm_inv_eng = inv_eng - 1;
	if (ring->type == sdma) {
		page_ring = amdgpu_sdma_get_page_ring(adev, ring->me); => returns
&adev->sdma.instance[i].page
		if (page_ring)
			page_ring->vm_inv_eng = inv_eng - 1;
	}	
	vm_inv_engs[vmhub] &= ~(1 << ring->vm_inv_eng);

Then skip any page rings in the generic loop.

	if (ring->type==sdma && amdgpu_sdma_is_page_queue(adev, ring)) continue;  -

Thanks,
Lijo

Quoted 70 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +6 -0
+		/* Do not allocate a separate VM invalidation engine for SDMA page rings.
+		 * Shared VM invalid engine with sdma gfx ring.
+		 */
+		ring->vm_inv_eng = inv_eng - 1;
+	} else {
 		ring->vm_inv_eng = inv_eng - 1;
 		vm_inv_engs[vmhub] &= ~(1 << ring->vm_inv_eng);
+	}
 
 		dev_info(adev->dev, "ring %s uses VM inv eng %u on hub %u\n",
 			 ring->name, ring->vm_inv_eng, ring->vm_hub);
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.c +18 -0
index 8de214a8ba6d..96df544feb67 100644
@@ -503,6 +503,24 @@ void amdgpu_sdma_sysfs_reset_mask_fini(struct amdgpu_device *adev)
 	}
 }
 
+/**
+* amdgpu_sdma_is_page_queue - Check if a ring is an SDMA page queue
+* @adev: Pointer to the AMDGPU device structure
+* @ring: Pointer to the ring structure to check
+*
+* This function checks if the given ring is an SDMA page queue.
+* It returns true if the ring is an SDMA page queue, false otherwise.
+*/
+bool amdgpu_sdma_is_page_queue(struct amdgpu_device *adev, struct amdgpu_ring* ring)
+{
+	int i = ring->me;
+
+	if (!adev->sdma.has_page_queue || i >= adev->sdma.num_instances)
+		return false;
+
+	return (ring == &adev->sdma.instance[i].page);
+}
+
 /**
  * amdgpu_sdma_register_on_reset_callbacks - Register SDMA reset callbacks
  * @funcs: Pointer to the callback structure containing pre_reset and post_reset functions
drivers/gpu/drm/amd/amdgpu/amdgpu_sdma.h +1 -0
index 7effc2673466..c2df9c3ab882 100644
@@ -194,4 +194,5 @@ int amdgpu_sdma_ras_sw_init(struct amdgpu_device *adev);
 void amdgpu_debugfs_sdma_sched_mask_init(struct amdgpu_device *adev);
 int amdgpu_sdma_sysfs_reset_mask_init(struct amdgpu_device *adev);
 void amdgpu_sdma_sysfs_reset_mask_fini(struct amdgpu_device *adev);
+bool amdgpu_sdma_is_page_queue(struct amdgpu_device *adev, struct amdgpu_ring* ring);
 #endif
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +2 -0
index 2aa87fdf715f..2599da8677da 100644
@@ -1000,6 +1000,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
 	 * to WA the Issue
 	 */
 
+	spin_lock(&adev->gmc.invalidate_lock);
 	/* TODO: It needs to continue working on debugging with semaphore for GFXHUB as well. */
 	if (use_semaphore)
 		/* a read return value of 1 means semaphore acuqire */
@@ -1030,6 +1031,7 @@ static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring,
 		amdgpu_ring_emit_wreg(ring, hub->vm_inv_eng0_sem +
 				      hub->eng_distance * eng, 0);
 
+	spin_unlock(&adev->gmc.invalidate_lock);
 	return pd_addr;
 }