drm/amdgpu/mes11: fix set_hw_resources_1 calculation
Subsystems (2)
Alex Deucher
maintainerPATCH 1/2 drm/amdgpu/mes11: fix set_hw_resources_1 calculation
It's GPU page size not CPU page size. In most cases they are the same, but not always. This can lead to overallocation on systems with larger pages.
--- drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +1 -1
@@ -743,7 +743,7 @@ static int mes_v11_0_set_hw_resources(struct amdgpu_mes *mes)static int mes_v11_0_set_hw_resources_1 (struct amdgpu_mes *mes) { -int size =128 *PAGE_SIZE ; +int size =128 *AMDGPU_GPU_PAGE_SIZE ;int ret =0 ;struct amdgpu_device *adev = mes->adev;union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_pkt;
Signature · 1 line
2.48.1
Alex Deucher
maintainerPATCH v4 2/2 drm/amdgpu/mes: Add cleaner shader fence address handling in MES for GFX11
From: Srinivasan Shanmugam <[email protected]>
This commit introduces enhancements to the handling of the cleaner shader fence in the AMDGPU MES driver:
- The MES (Microcode Execution Scheduler) now sends a PM4 packet to the KIQ (Kernel Interface Queue) to request the cleaner shader, ensuring that requests are handled in a controlled manner and avoiding the race conditions.
- The CP (Compute Processor) firmware has been updated to use a private bus for accessing specific registers, avoiding unnecessary operations that could lead to issues in VF (Virtual Function) mode.
- The cleaner shader fence memory address is now set correctly in the mes_set_hw_res_pkt structure, allowing for proper synchronization of the cleaner shader execution. This is done by calculating the address using the write-back memory base address and the cleaner fence offset.
--- drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +12 -5
@@ -754,7 +754,7 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes) mes_set_hw_res_pkt.header.dwsize =API_FRAME_SIZE_IN_DWORDS ; mes_set_hw_res_pkt.enable_mes_info_ctx =1 ; - ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE, + ret = amdgpu_bo_create_kernel(adev, size + AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM, &mes->resource_1, &mes->resource_1_gpu_addr,
@@ -765,7 +765,10 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes) } mes_set_hw_res_pkt.mes_info_ctx_mc_addr = mes->resource_1_gpu_addr; - mes_set_hw_res_pkt.mes_info_ctx_size = mes->resource_1->tbo.base.size; + mes_set_hw_res_pkt.mes_info_ctx_size = size; + mes_set_hw_res_pkt.cleaner_shader_fence_mc_addr = + mes->resource_1_gpu_addr + size; +return mes_v11_0_submit_pkt_and_poll_completion (mes, &mes_set_hw_res_pkt,sizeof (mes_set_hw_res_pkt), offsetof(union MESAPI_SET_HW_RESOURCES_1 , api_status));
@@ -1632,7 +1635,8 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)if (r) goto failure; -if (amdgpu_sriov_is_mes_info_enable (adev)) { +if (amdgpu_sriov_is_mes_info_enable (adev) || + adev->gfx.enable_cleaner_shader) { r =mes_v11_0_set_hw_resources_1 (&adev->mes);if (r) {DRM_ERROR ("failed mes_v11_0_set_hw_resources_1, r=%d\n" , r);
@@ -1665,10 +1669,13 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)static int mes_v11_0_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -if (amdgpu_sriov_is_mes_info_enable (adev)) { + +if (amdgpu_sriov_is_mes_info_enable (adev) || + adev->gfx.enable_cleaner_shader) {amdgpu_bo_free_kernel (&adev->mes.resource_1, &adev->mes.resource_1_gpu_addr, - &adev->mes.resource_1_addr); + &adev->mes.resource_1_addr); } +return 0 ; }
Signature · 1 line
2.48.1
RE: [PATCH V4 2/2] drm/amdgpu/mes: Add cleaner shader fence address handling in MES for GFX11
[AMD Official Use Only - AMD Internal Distribution Only]
Might need to update the commit message since this change don't use the write-back memory and the package is set_hw_res_1.
Other than that , it looks good to me . And I think we need a similar change for gfx12
Regards
Shaoyun.liu
-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Monday, February 10, 2025 11:28 AM
To: [email protected]
Cc: SHANMUGAM, SRINIVASAN <[email protected]>; cao, lin <[email protected]>; Chen, JingWen (Wayne) <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Liu, Shaoyun <[email protected]>
Subject: [PATCH V4 2/2] drm/amdgpu/mes: Add cleaner shader fence address handling in MES for GFX11
From: Srinivasan Shanmugam <[email protected]>
This commit introduces enhancements to the handling of the cleaner shader fence in the AMDGPU MES driver:
- The MES (Microcode Execution Scheduler) now sends a PM4 packet to the KIQ (Kernel Interface Queue) to request the cleaner shader, ensuring that requests are handled in a controlled manner and avoiding the race conditions.
- The CP (Compute Processor) firmware has been updated to use a private bus for accessing specific registers, avoiding unnecessary operations that could lead to issues in VF (Virtual Function) mode.
- The cleaner shader fence memory address is now set correctly in the mes_set_hw_res_pkt structure, allowing for proper synchronization of the cleaner shader execution. This is done by calculating the address using the write-back memory base address and the cleaner fence offset.
--- drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2 -1
@@ -754,7 +754,7 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes) mes_set_hw_res_pkt.header.dwsize =API_FRAME_SIZE_IN_DWORDS ; mes_set_hw_res_pkt.enable_mes_info_ctx =1 ; - ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE, + ret = amdgpu_bo_create_kernel(adev, size + AMDGPU_GPU_PAGE_SIZE, +PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM, &mes->resource_1,
&mes->resource_1_gpu_addr,
@@ -765,7 +765,10 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes)
}
mes_set_hw_res_pkt.mes_info_ctx_mc_addr = mes->resource_1_gpu_addr;
- mes_set_hw_res_pkt.mes_info_ctx_size = mes->resource_1->tbo.base.size;
+ mes_set_hw_res_pkt.mes_info_ctx_size = size;
+ mes_set_hw_res_pkt.cleaner_shader_fence_mc_addr =
+ mes->resource_1_gpu_addr + size;
+
return mes_v11_0_submit_pkt_and_poll_completion(mes,
&mes_set_hw_res_pkt, sizeof(mes_set_hw_res_pkt),
offsetof(union MESAPI_SET_HW_RESOURCES_1, api_status)); @@ -1632,7 +1635,8 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)
if (r)
goto failure;- if (amdgpu_sriov_is_mes_info_enable(adev)) {
+ if (amdgpu_sriov_is_mes_info_enable(adev) ||
+ adev->gfx.enable_cleaner_shader) {
r = mes_v11_0_set_hw_resources_1(&adev->mes);
if (r) {
DRM_ERROR("failed mes_v11_0_set_hw_resources_1, r=%d\n", r); @@ -1665,10 +1669,13 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block) static int mes_v11_0_hw_fini(struct amdgpu_ip_block *ip_block) {
struct amdgpu_device *adev = ip_block->adev;
- if (amdgpu_sriov_is_mes_info_enable(adev)) {
+
+ if (amdgpu_sriov_is_mes_info_enable(adev) ||
+ adev->gfx.enable_cleaner_shader) {
amdgpu_bo_free_kernel(&adev->mes.resource_1, &adev->mes.resource_1_gpu_addr,
- &adev->mes.resource_1_addr);
+ &adev->mes.resource_1_addr);
}
+
return 0;}
--
2.48.1
Re: [PATCH V4 2/2] drm/amdgpu/mes: Add cleaner shader fence address handling in MES for GFX11
Quoted 4 lines · Shaoyun
[AMD Official Use Only - AMD Internal Distribution Only]
Might need to update the commit message since this change don't use the write-back memory and the package is
set_hw_res_1.
Fixed locally. Thanks.
Alex
Quoted 91 lines
Other than that , it looks good to me . And I think we need a similar change for gfx12
Regards
Shaoyun.liu-----Original Message-----
From: Deucher, Alexander <[email protected]>
Sent: Monday, February 10, 2025 11:28 AM
To: [email protected]
Cc: SHANMUGAM, SRINIVASAN <[email protected]>; cao, lin <[email protected]>; Chen, JingWen (Wayne) <[email protected]>; Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; Liu, Shaoyun <[email protected]>
Subject: [PATCH V4 2/2] drm/amdgpu/mes: Add cleaner shader fence address handling in MES for GFX11From: Srinivasan Shanmugam <[email protected]>
This commit introduces enhancements to the handling of the cleaner shader fence in the AMDGPU MES driver:
- The MES (Microcode Execution Scheduler) now sends a PM4 packet to the KIQ (Kernel Interface Queue) to request the cleaner shader, ensuring that requests are handled in a controlled manner and avoiding the race conditions.
- The CP (Compute Processor) firmware has been updated to use a private bus for accessing specific registers, avoiding unnecessary operations that could lead to issues in VF (Virtual Function) mode.
- The cleaner shader fence memory address is now set correctly in themes_set_hw_res_pktstructure, allowing for proper synchronization of the cleaner shader execution. This is done by calculating the address using the write-back memory base address and the cleaner fence offset.Cc lin cao <[email protected]>Cc Jingwen Chen <[email protected]>Cc Christian König <[email protected]>Cc Alex Deucher <[email protected]>Suggested-by Shaoyun Liu <[email protected]>Signed-off-by Srinivasan Shanmugam <[email protected]>Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +6
-2@@ -754,7 +754,7 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes) mes_set_hw_res_pkt.header.dwsize =API_FRAME_SIZE_IN_DWORDS ; mes_set_hw_res_pkt.enable_mes_info_ctx =1 ; - ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE, + ret = amdgpu_bo_create_kernel(adev, size + AMDGPU_GPU_PAGE_SIZE, +PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM, &mes->resource_1, &mes->resource_1_gpu_addr,@@ -765,7 +765,10 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes) } mes_set_hw_res_pkt.mes_info_ctx_mc_addr = mes->resource_1_gpu_addr; - mes_set_hw_res_pkt.mes_info_ctx_size = mes->resource_1->tbo.base.size; + mes_set_hw_res_pkt.mes_info_ctx_size = size; + mes_set_hw_res_pkt.cleaner_shader_fence_mc_addr = + mes->resource_1_gpu_addr + size; +return mes_v11_0_submit_pkt_and_poll_completion (mes, &mes_set_hw_res_pkt,sizeof (mes_set_hw_res_pkt), offsetof(union MESAPI_SET_HW_RESOURCES_1, api_status)); @@ -1632,7 +1635,8 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)if (r) goto failure;drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +7
-4-if (amdgpu_sriov_is_mes_info_enable (adev)) { +if (amdgpu_sriov_is_mes_info_enable (adev) || + adev->gfx.enable_cleaner_shader) { r =mes_v11_0_set_hw_resources_1 (&adev->mes);if (r) { DRM_ERROR("failed mes_v11_0_set_hw_resources_1, r=%d\n", r); @@ -1665,10 +1669,13 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block) static int mes_v11_0_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -if (amdgpu_sriov_is_mes_info_enable (adev)) { + +if (amdgpu_sriov_is_mes_info_enable (adev) || + adev->gfx.enable_cleaner_shader) {amdgpu_bo_free_kernel (&adev->mes.resource_1, &adev->mes.resource_1_gpu_addr, - &adev->mes.resource_1_addr); + &adev->mes.resource_1_addr); } +return 0 ; } --2.48.1
Re: [PATCH V4 2/2] drm/amdgpu/mes: Add cleaner shader fence address handling in MES for GFX11
In reply to Alex DeucherAm 10.02.25 um 17:27 schrieb Alex Deucher:
Quoted 33 lines
From: Srinivasan Shanmugam <[email protected]>
This commit introduces enhancements to the handling of the cleaner shader fence in the AMDGPU MES driver:
- The MES (Microcode Execution Scheduler) now sends a PM4 packet to the KIQ (Kernel Interface Queue) to request the cleaner shader, ensuring that requests are handled in a controlled manner and avoiding the race conditions.
- The CP (Compute Processor) firmware has been updated to use a private bus for accessing specific registers, avoiding unnecessary operations that could lead to issues in VF (Virtual Function) mode.
- The cleaner shader fence memory address is now set correctly in themes_set_hw_res_pktstructure, allowing for proper synchronization of the cleaner shader execution. This is done by calculating the address using the write-back memory base address and the cleaner fence offset.Cc lin cao <[email protected]>Cc Jingwen Chen <[email protected]>Cc Christian König <[email protected]>Cc Alex Deucher <[email protected]>Suggested-by Shaoyun Liu <[email protected]>Signed-off-by Srinivasan Shanmugam <[email protected]>Signed-off-by Alex Deucher <[email protected]>--- drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +0
-0
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes) · line 757
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +1
-1@@ -754,7 +754,7 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes) mes_set_hw_res_pkt.header.dwsize =API_FRAME_SIZE_IN_DWORDS ; mes_set_hw_res_pkt.enable_mes_info_ctx =1 ; - ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE, + ret = amdgpu_bo_create_kernel(adev, size + AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE,
You might want to adjust the size calculation earlier in the function instead of here.
Christian.
Quoted 41 lines
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +11
-4AMDGPU_GEM_DOMAIN_VRAM , &mes->resource_1, &mes->resource_1_gpu_addr,@@ -765,7 +765,10 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes) } mes_set_hw_res_pkt.mes_info_ctx_mc_addr = mes->resource_1_gpu_addr; - mes_set_hw_res_pkt.mes_info_ctx_size = mes->resource_1->tbo.base.size; + mes_set_hw_res_pkt.mes_info_ctx_size = size; + mes_set_hw_res_pkt.cleaner_shader_fence_mc_addr = + mes->resource_1_gpu_addr + size; +return mes_v11_0_submit_pkt_and_poll_completion (mes, &mes_set_hw_res_pkt,sizeof (mes_set_hw_res_pkt), offsetof(union MESAPI_SET_HW_RESOURCES_1 , api_status));@@ -1632,7 +1635,8 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)if (r) goto failure; -if (amdgpu_sriov_is_mes_info_enable (adev)) { +if (amdgpu_sriov_is_mes_info_enable (adev) || + adev->gfx.enable_cleaner_shader) { r =mes_v11_0_set_hw_resources_1 (&adev->mes);if (r) {DRM_ERROR ("failed mes_v11_0_set_hw_resources_1, r=%d\n" , r);@@ -1665,10 +1669,13 @@ static int mes_v11_0_hw_init(struct amdgpu_ip_block *ip_block)static int mes_v11_0_hw_fini (struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; -if (amdgpu_sriov_is_mes_info_enable (adev)) { + +if (amdgpu_sriov_is_mes_info_enable (adev) || + adev->gfx.enable_cleaner_shader) {amdgpu_bo_free_kernel (&adev->mes.resource_1, &adev->mes.resource_1_gpu_addr, - &adev->mes.resource_1_addr); + &adev->mes.resource_1_addr); } +return 0 ; }
Am 10.02.25 um 17:27 schrieb Alex Deucher:
Quoted 7 lines
It's GPU page size not CPU page size. In most cases they are the same, but not always. This can lead to overallocation on systems with larger pages.
Cc Srinivasan Shanmugam <[email protected]>Cc Christian König <[email protected]>Signed-off-by Alex Deucher <[email protected]>
Quoted 17 lines
--- drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +1
-1@@ -743,7 +743,7 @@ static int mes_v11_0_set_hw_resources(struct amdgpu_mes *mes)static int mes_v11_0_set_hw_resources_1 (struct amdgpu_mes *mes) { -int size =128 *PAGE_SIZE ; +int size =128 *AMDGPU_GPU_PAGE_SIZE ;int ret =0 ;struct amdgpu_device *adev = mes->adev;union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_pkt;