drm/amd/amdgpu: Increase max rings to enable SDMA page ring
Subsystems (2)
PATCH 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
@@ -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
PATCH 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.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 9 +++++++++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 ++ 2 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +9 -0
@@ -601,8 +601,17 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)return -EINVAL ; } +if (ring->funcs->type ==AMDGPU_RING_TYPE_SDMA && + adev->sdma.has_page_queue && + (strncmp (ring->name,"sdma" ,4 ) ==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/gmc_v9_0.c +2 -0
@@ -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
Re: [PATCH 2/2] drm/amdgpu: Optimize VM invalidation engine allocation and synchronize GPU TLB flush
Quoted 23 lines · On 2/19/2025 11:50 AM, [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.
Usespin_lockandspin_unlockto 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.Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 9 +++++++++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 ++ 2 files changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0
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,17 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)return -EINVAL ; } + if (ring->funcs->type == AMDGPU_RING_TYPE_SDMA &&
I think better would be to combine ring type with something like this
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);
}Thanks,
Lijo
Quoted 33 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +8
-0+ adev->sdma.has_page_queue && + (strncmp(ring->name, "sdma", 4) == 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/gmc_v9_0.c +2
-0@@ -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; }
Re: [PATCH 2/2] drm/amdgpu: Optimize VM invalidation engine allocation and synchronize GPU TLB flush
Quoted 33 lines · Lijo
Quoted 23 lines · On 2/19/2025 11:50 AM, [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.
Usespin_lockandspin_unlockto 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.Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 9 +++++++++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 ++ 2 files changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0drivers/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,17 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)return -EINVAL ; } + if (ring->funcs->type == AMDGPU_RING_TYPE_SDMA &&I think better would be to combine ring type with something like this
Quoted 6 lines
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)
Correction -
(i >= adev->sdma.num_instances)
Thanks,
Lijo
Quoted 42 lines
return false; return (ring == &adev->sdma.instance[i].page); }Thanks,
LijoQuoted 33 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +8
-0+ adev->sdma.has_page_queue && + (strncmp(ring->name, "sdma", 4) == 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/gmc_v9_0.c +2
-0@@ -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; }
Christian König
maintainerRe: [PATCH 2/2] drm/amdgpu: Optimize VM invalidation engine allocation and synchronize GPU TLB flush
In reply to [email protected]Am 19.02.25 um 07:20 schrieb [email protected]:
Quoted 23 lines
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.
Usespin_lockandspin_unlockto 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.Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 9 +++++++++ drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c | 2 ++ 2 files changed, 11 insertions(+)drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0
-0
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev) · line 606
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +3
-0@@ -601,8 +601,17 @@ int amdgpu_gmc_allocate_vm_inv_eng(struct amdgpu_device *adev)return -EINVAL ; } +if (ring->funcs->type ==AMDGPU_RING_TYPE_SDMA && + adev->sdma.has_page_queue && + (strncmp (ring->name,"sdma" ,4 ) ==0 )) {
Clear NAK to that. *Never ever* use strncmp for a technical decision inside the kernel.
Lijo's suggestion sound much cleaner to me.
Quoted 16 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/gmc_v9_0.c +0
-0
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c static uint64_t gmc_v9_0_emit_flush_gpu_tlb(struct amdgpu_ring *ring, · line 1003
Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1
-0@@ -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);
That makes no sense at all. The commands are written into the ring and executed asynchronously after the lock is already dropped again.
Please completely drop that.
Regards,
Christian.
Quoted 11 lines
drivers/gpu/drm/amd/amdgpu/gmc_v9_0.c +1
-0/* 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; }