Skip to contentSkip to conversation

drm/amdgpu/mes11: allocate hw_resource_1 buffer once

PATCH In review Alex Deucher 3 participants 10 messages Feb 14, 2025 – Feb 15, 2025

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/2 drm/amdgpu/mes11: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 52 +++++++++++++-------------
 1 file changed, 26 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +26 -26
index 26af0af718b5e..530371e6a7aee 100644
@@ -64,6 +64,7 @@ static int mes_v11_0_kiq_hw_fini(struct amdgpu_device *adev);
 
 #define MES_EOP_SIZE   2048
 #define GFX_MES_DRAM_SIZE	0x80000
+#define MES11_HW_RESOURCE_1_SIZE (128 * AMDGPU_GPU_PAGE_SIZE)
 
 static void mes_v11_0_ring_set_wptr(struct amdgpu_ring *ring)
 {
@@ -743,11 +744,6 @@ 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)
 {
-	unsigned int hw_rsrc_size = 128 * AMDGPU_GPU_PAGE_SIZE;
-	/* add a page for the cleaner shader fence */
-	unsigned int alloc_size = hw_rsrc_size + AMDGPU_GPU_PAGE_SIZE;
-	int ret = 0;
-	struct amdgpu_device *adev = mes->adev;
 	union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_pkt;
 	memset(&mes_set_hw_res_pkt, 0, sizeof(mes_set_hw_res_pkt));
 
@@ -755,21 +751,10 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes)
 	mes_set_hw_res_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
 	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, alloc_size, PAGE_SIZE,
-				AMDGPU_GEM_DOMAIN_VRAM,
-				&mes->resource_1,
-				&mes->resource_1_gpu_addr,
-				&mes->resource_1_addr);
-	if (ret) {
-		dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
-		return ret;
-	}
-
 	mes_set_hw_res_pkt.mes_info_ctx_mc_addr = mes->resource_1_gpu_addr;
-	mes_set_hw_res_pkt.mes_info_ctx_size = hw_rsrc_size;
+	mes_set_hw_res_pkt.mes_info_ctx_size = MES11_HW_RESOURCE_1_SIZE;
 	mes_set_hw_res_pkt.cleaner_shader_fence_mc_addr =
-		mes->resource_1_gpu_addr + hw_rsrc_size;
+		mes->resource_1_gpu_addr + MES11_HW_RESOURCE_1_SIZE;
 
 	return mes_v11_0_submit_pkt_and_poll_completion(mes,
 			&mes_set_hw_res_pkt, sizeof(mes_set_hw_res_pkt),
@@ -1442,6 +1427,23 @@ static int mes_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
 	if (r)
 		return r;
 
+	if (amdgpu_sriov_is_mes_info_enable(adev) ||
+	    adev->gfx.enable_cleaner_shader) {
+		int ret;
+
+		ret = amdgpu_bo_create_kernel(adev,
+					      MES11_HW_RESOURCE_1_SIZE + AMDGPU_GPU_PAGE_SIZE,
+					      PAGE_SIZE,
+					      AMDGPU_GEM_DOMAIN_VRAM,
+					      &adev->mes.resource_1,
+					      &adev->mes.resource_1_gpu_addr,
+					      &adev->mes.resource_1_addr);
+		if (ret) {
+			dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+			return ret;
+		}
+	}
+
 	return 0;
 }
 
@@ -1450,6 +1452,12 @@ static int mes_v11_0_sw_fini(struct amdgpu_ip_block *ip_block)
 	struct amdgpu_device *adev = ip_block->adev;
 	int pipe;
 
+	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);
+	}
+
 	for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
 		kfree(adev->mes.mqd_backup[pipe]);
 
@@ -1670,14 +1678,6 @@ 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) ||
-	    adev->gfx.enable_cleaner_shader) {
-		amdgpu_bo_free_kernel(&adev->mes.resource_1, &adev->mes.resource_1_gpu_addr,
-				      &adev->mes.resource_1_addr);
-	}
-
 	return 0;
 }
 
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH 2/2 drm/amdgpu/mes12: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 39 +++++++++++++-------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +19 -20
index 8dbab3834d82d..6db88584dd529 100644
@@ -678,9 +678,6 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
 
 static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)
 {
-	unsigned int alloc_size = AMDGPU_GPU_PAGE_SIZE;
-	int ret = 0;
-	struct amdgpu_device *adev = mes->adev;
 	union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_1_pkt;
 
 	memset(&mes_set_hw_res_1_pkt, 0, sizeof(mes_set_hw_res_1_pkt));
@@ -689,17 +686,6 @@ static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)
 	mes_set_hw_res_1_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
 	mes_set_hw_res_1_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
 	mes_set_hw_res_1_pkt.mes_kiq_unmap_timeout = 0xa;
-
-	ret = amdgpu_bo_create_kernel(adev, alloc_size, PAGE_SIZE,
-				AMDGPU_GEM_DOMAIN_VRAM,
-				&mes->resource_1,
-				&mes->resource_1_gpu_addr,
-				&mes->resource_1_addr);
-	if (ret) {
-		dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
-		return ret;
-	}
-
 	mes_set_hw_res_1_pkt.cleaner_shader_fence_mc_addr =
 		mes->resource_1_gpu_addr;
 
@@ -1550,6 +1536,20 @@ static int mes_v12_0_sw_init(struct amdgpu_ip_block *ip_block)
 			return r;
 	}
 
+	if (adev->enable_uni_mes) {
+		int ret;
+
+		ret = amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE,
+					      AMDGPU_GEM_DOMAIN_VRAM,
+					      &adev->mes.resource_1,
+					      &adev->mes.resource_1_gpu_addr,
+					      &adev->mes.resource_1_addr);
+		if (ret) {
+			dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+			return ret;
+		}
+	}
+
 	return 0;
 }
 
@@ -1558,6 +1558,11 @@ static int mes_v12_0_sw_fini(struct amdgpu_ip_block *ip_block)
 	struct amdgpu_device *adev = ip_block->adev;
 	int pipe;
 
+	if (adev->enable_uni_mes)
+		amdgpu_bo_free_kernel(&adev->mes.resource_1,
+				      &adev->mes.resource_1_gpu_addr,
+				      &adev->mes.resource_1_addr);
+
 	for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
 		kfree(adev->mes.mqd_backup[pipe]);
 
@@ -1786,12 +1791,6 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)
 
 static int mes_v12_0_hw_fini(struct amdgpu_ip_block *ip_block)
 {
-	struct amdgpu_device *adev = ip_block->adev;
-
-	if (adev->enable_uni_mes)
-		amdgpu_bo_free_kernel(&adev->mes.resource_1,
-				      &adev->mes.resource_1_gpu_addr,
-				      &adev->mes.resource_1_addr);
 	return 0;
 }
 
Signature · 1 line
2.48.1
#2 lore raw

RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I'd suggest remove the enable_uni_mes check, set_hw_resource_1 is always required for gfx12 and up. Especially after add the cleaner_shader_fence_addr there.

Regards
Shaoyun.liu

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Friday, February 14, 2025 10:19 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 39 +++++++++++++-------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +0 -3
index 8dbab3834d82d..6db88584dd529 100644
@@ -678,9 +678,6 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
 
 static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)  {
-       unsigned int alloc_size = AMDGPU_GPU_PAGE_SIZE;
-       int ret = 0;
-       struct amdgpu_device *adev = mes->adev;
        union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_1_pkt;
 
        memset(&mes_set_hw_res_1_pkt, 0, sizeof(mes_set_hw_res_1_pkt)); @@ -689,17 +686,6 @@ static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)
        mes_set_hw_res_1_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
        mes_set_hw_res_1_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
        mes_set_hw_res_1_pkt.mes_kiq_unmap_timeout = 0xa;
-
-       ret = amdgpu_bo_create_kernel(adev, alloc_size, PAGE_SIZE,
-                               AMDGPU_GEM_DOMAIN_VRAM,
-                               &mes->resource_1,
-                               &mes->resource_1_gpu_addr,
-                               &mes->resource_1_addr);

- if (ret) {
- dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
- return ret;
- }
-

        mes_set_hw_res_1_pkt.cleaner_shader_fence_mc_addr =
                mes->resource_1_gpu_addr;

@@ -1550,6 +1536,20 @@ static int mes_v12_0_sw_init(struct amdgpu_ip_block *ip_block)

                        return r;
        }

+ if (adev->enable_uni_mes) {
+ int ret;
+
+ ret = amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE,

+                                             AMDGPU_GEM_DOMAIN_VRAM,
+                                             &adev->mes.resource_1,
+                                             &adev->mes.resource_1_gpu_addr,
+                                             &adev->mes.resource_1_addr);

+ if (ret) {
+ dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+ return ret;
+ }
+ }
+

        return 0;

}

@@ -1558,6 +1558,11 @@ static int mes_v12_0_sw_fini(struct amdgpu_ip_block *ip_block)

        struct amdgpu_device *adev = ip_block->adev;
        int pipe;

+ if (adev->enable_uni_mes)
+ amdgpu_bo_free_kernel(&adev->mes.resource_1,
+ &adev->mes.resource_1_gpu_addr,
+ &adev->mes.resource_1_addr);
+

        for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
                kfree(adev->mes.mqd_backup[pipe]);

@@ -1786,12 +1791,6 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)

static int mes_v12_0_hw_fini(struct amdgpu_ip_block *ip_block) {
- struct amdgpu_device *adev = ip_block->adev;
-
- if (adev->enable_uni_mes)
- amdgpu_bo_free_kernel(&adev->mes.resource_1,
- &adev->mes.resource_1_gpu_addr,

-                                     &adev->mes.resource_1_addr);
        return 0;

}

--
2.48.1

author maintainer
#3 lore raw

Re: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I can add that as a follow up patch as I don't want to change the current behavior to avoid a potential regression. Should we submit both the resource and resource_1 packets all the time?

Thanks,

Alex

________________________________
From: Liu, Shaoyun <[email protected]>
Sent: Friday, February 14, 2025 11:45 AM
To: Deucher, Alexander <[email protected]>; [email protected] <[email protected]>
Cc: Deucher, Alexander <[email protected]>
Subject: RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I'd suggest remove the enable_uni_mes check, set_hw_resource_1 is always required for gfx12 and up. Especially after add the cleaner_shader_fence_addr there.

Regards
Shaoyun.liu

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Friday, February 14, 2025 10:19 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 39 +++++++++++++-------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +0 -3
index 8dbab3834d82d..6db88584dd529 100644
@@ -678,9 +678,6 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
 
 static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)  {
-       unsigned int alloc_size = AMDGPU_GPU_PAGE_SIZE;
-       int ret = 0;
-       struct amdgpu_device *adev = mes->adev;
        union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_1_pkt;
 
        memset(&mes_set_hw_res_1_pkt, 0, sizeof(mes_set_hw_res_1_pkt)); @@ -689,17 +686,6 @@ static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)
        mes_set_hw_res_1_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
        mes_set_hw_res_1_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
        mes_set_hw_res_1_pkt.mes_kiq_unmap_timeout = 0xa;
-
-       ret = amdgpu_bo_create_kernel(adev, alloc_size, PAGE_SIZE,
-                               AMDGPU_GEM_DOMAIN_VRAM,
-                               &mes->resource_1,
-                               &mes->resource_1_gpu_addr,
-                               &mes->resource_1_addr);

- if (ret) {
- dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
- return ret;
- }
-

        mes_set_hw_res_1_pkt.cleaner_shader_fence_mc_addr =
                mes->resource_1_gpu_addr;

@@ -1550,6 +1536,20 @@ static int mes_v12_0_sw_init(struct amdgpu_ip_block *ip_block)

                        return r;
        }

+ if (adev->enable_uni_mes) {
+ int ret;
+
+ ret = amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE,

+                                             AMDGPU_GEM_DOMAIN_VRAM,
+                                             &adev->mes.resource_1,
+                                             &adev->mes.resource_1_gpu_addr,
+                                             &adev->mes.resource_1_addr);

+ if (ret) {
+ dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+ return ret;
+ }
+ }
+

        return 0;

}

@@ -1558,6 +1558,11 @@ static int mes_v12_0_sw_fini(struct amdgpu_ip_block *ip_block)

        struct amdgpu_device *adev = ip_block->adev;
        int pipe;

+ if (adev->enable_uni_mes)
+ amdgpu_bo_free_kernel(&adev->mes.resource_1,
+ &adev->mes.resource_1_gpu_addr,
+ &adev->mes.resource_1_addr);
+

        for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
                kfree(adev->mes.mqd_backup[pipe]);

@@ -1786,12 +1791,6 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)

static int mes_v12_0_hw_fini(struct amdgpu_ip_block *ip_block) {
- struct amdgpu_device *adev = ip_block->adev;
-
- if (adev->enable_uni_mes)
- amdgpu_bo_free_kernel(&adev->mes.resource_1,
- &adev->mes.resource_1_gpu_addr,

-                                     &adev->mes.resource_1_addr);
        return 0;

}

--
2.48.1

Reviewed-by
#4 lore raw

RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

Ok . From MES point of view , we expecting both set_hw_resource and set_hw_resource_1 been called all the time.

From: Deucher, Alexander <[email protected]>
Sent: Friday, February 14, 2025 11:53 AM
To: Liu, Shaoyun <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I can add that as a follow up patch as I don't want to change the current behavior to avoid a potential regression. Should we submit both the resource and resource_1 packets all the time?

Thanks,

Alex

________________________________
From: Liu, Shaoyun <[email protected]<mailto:[email protected]>>
Sent: Friday, February 14, 2025 11:45 AM
To: Deucher, Alexander <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Subject: RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I'd suggest remove the enable_uni_mes check, set_hw_resource_1 is always required for gfx12 and up. Especially after add the cleaner_shader_fence_addr there.

Regards
Shaoyun.liu

-----Original Message-----
From: amd-gfx <[email protected]<mailto:[email protected]>> On Behalf Of Alex Deucher
Sent: Friday, February 14, 2025 10:19 AM
To: [email protected]<mailto:[email protected]>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Subject: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 39 +++++++++++++-------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +0 -3
index 8dbab3834d82d..6db88584dd529 100644
@@ -678,9 +678,6 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
 
 static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)  {
-       unsigned int alloc_size = AMDGPU_GPU_PAGE_SIZE;
-       int ret = 0;
-       struct amdgpu_device *adev = mes->adev;
        union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_1_pkt;
 
        memset(&mes_set_hw_res_1_pkt, 0, sizeof(mes_set_hw_res_1_pkt)); @@ -689,17 +686,6 @@ static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)
        mes_set_hw_res_1_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
        mes_set_hw_res_1_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
        mes_set_hw_res_1_pkt.mes_kiq_unmap_timeout = 0xa;
-
-       ret = amdgpu_bo_create_kernel(adev, alloc_size, PAGE_SIZE,
-                               AMDGPU_GEM_DOMAIN_VRAM,
-                               &mes->resource_1,
-                               &mes->resource_1_gpu_addr,
-                               &mes->resource_1_addr);

- if (ret) {
- dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
- return ret;
- }
-

        mes_set_hw_res_1_pkt.cleaner_shader_fence_mc_addr =
                mes->resource_1_gpu_addr;

@@ -1550,6 +1536,20 @@ static int mes_v12_0_sw_init(struct amdgpu_ip_block *ip_block)

                        return r;
        }

+ if (adev->enable_uni_mes) {
+ int ret;
+
+ ret = amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE,

+                                             AMDGPU_GEM_DOMAIN_VRAM,
+                                             &adev->mes.resource_1,
+                                             &adev->mes.resource_1_gpu_addr,
+                                             &adev->mes.resource_1_addr);

+ if (ret) {
+ dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+ return ret;
+ }
+ }
+

        return 0;

}

@@ -1558,6 +1558,11 @@ static int mes_v12_0_sw_fini(struct amdgpu_ip_block *ip_block)

        struct amdgpu_device *adev = ip_block->adev;
        int pipe;

+ if (adev->enable_uni_mes)
+ amdgpu_bo_free_kernel(&adev->mes.resource_1,
+ &adev->mes.resource_1_gpu_addr,
+ &adev->mes.resource_1_addr);
+

        for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
                kfree(adev->mes.mqd_backup[pipe]);

@@ -1786,12 +1791,6 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)

static int mes_v12_0_hw_fini(struct amdgpu_ip_block *ip_block) {
- struct amdgpu_device *adev = ip_block->adev;
-
- if (adev->enable_uni_mes)
- amdgpu_bo_free_kernel(&adev->mes.resource_1,
- &adev->mes.resource_1_gpu_addr,

-                                     &adev->mes.resource_1_addr);
        return 0;

}

--
2.48.1

author maintainer Reviewed-by Shaoyun.liu
#5 lore raw

Re: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

Does it matter which pipe we use for these packets?

Alex

________________________________
From: Liu, Shaoyun <[email protected]>
Sent: Friday, February 14, 2025 12:36 PM
To: Deucher, Alexander <[email protected]>; [email protected] <[email protected]>
Subject: RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

Ok . From MES point of view , we expecting both set_hw_resource and set_hw_resource_1 been called all the time.

From: Deucher, Alexander <[email protected]>
Sent: Friday, February 14, 2025 11:53 AM
To: Liu, Shaoyun <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I can add that as a follow up patch as I don't want to change the current behavior to avoid a potential regression. Should we submit both the resource and resource_1 packets all the time?

Thanks,

Alex

________________________________

From: Liu, Shaoyun <[email protected]<mailto:[email protected]>>
Sent: Friday, February 14, 2025 11:45 AM
To: Deucher, Alexander <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Subject: RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I'd suggest remove the enable_uni_mes check, set_hw_resource_1 is always required for gfx12 and up. Especially after add the cleaner_shader_fence_addr there.

Regards
Shaoyun.liu

-----Original Message-----
From: amd-gfx <[email protected]<mailto:[email protected]>> On Behalf Of Alex Deucher
Sent: Friday, February 14, 2025 10:19 AM
To: [email protected]<mailto:[email protected]>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Subject: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 39 +++++++++++++-------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +0 -3
index 8dbab3834d82d..6db88584dd529 100644
@@ -678,9 +678,6 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
 
 static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)  {
-       unsigned int alloc_size = AMDGPU_GPU_PAGE_SIZE;
-       int ret = 0;
-       struct amdgpu_device *adev = mes->adev;
        union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_1_pkt;
 
        memset(&mes_set_hw_res_1_pkt, 0, sizeof(mes_set_hw_res_1_pkt)); @@ -689,17 +686,6 @@ static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)
        mes_set_hw_res_1_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
        mes_set_hw_res_1_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
        mes_set_hw_res_1_pkt.mes_kiq_unmap_timeout = 0xa;
-
-       ret = amdgpu_bo_create_kernel(adev, alloc_size, PAGE_SIZE,
-                               AMDGPU_GEM_DOMAIN_VRAM,
-                               &mes->resource_1,
-                               &mes->resource_1_gpu_addr,
-                               &mes->resource_1_addr);

- if (ret) {
- dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
- return ret;
- }
-

        mes_set_hw_res_1_pkt.cleaner_shader_fence_mc_addr =
                mes->resource_1_gpu_addr;

@@ -1550,6 +1536,20 @@ static int mes_v12_0_sw_init(struct amdgpu_ip_block *ip_block)

                        return r;
        }

+ if (adev->enable_uni_mes) {
+ int ret;
+
+ ret = amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE,

+                                             AMDGPU_GEM_DOMAIN_VRAM,
+                                             &adev->mes.resource_1,
+                                             &adev->mes.resource_1_gpu_addr,
+                                             &adev->mes.resource_1_addr);

+ if (ret) {
+ dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+ return ret;
+ }
+ }
+

        return 0;

}

@@ -1558,6 +1558,11 @@ static int mes_v12_0_sw_fini(struct amdgpu_ip_block *ip_block)

        struct amdgpu_device *adev = ip_block->adev;
        int pipe;

+ if (adev->enable_uni_mes)
+ amdgpu_bo_free_kernel(&adev->mes.resource_1,
+ &adev->mes.resource_1_gpu_addr,
+ &adev->mes.resource_1_addr);
+

        for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
                kfree(adev->mes.mqd_backup[pipe]);

@@ -1786,12 +1791,6 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)

static int mes_v12_0_hw_fini(struct amdgpu_ip_block *ip_block) {
- struct amdgpu_device *adev = ip_block->adev;
-
- if (adev->enable_uni_mes)
- amdgpu_bo_free_kernel(&adev->mes.resource_1,
- &adev->mes.resource_1_gpu_addr,

-                                     &adev->mes.resource_1_addr);
        return 0;

}

--
2.48.1

Reviewed-by Shaoyun.liu
#6 lore raw

RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

Oh, you right. It's only for unified MES , for none-unified , it will still use the kiq from CP directly on pipe1 . So there is no MES API for it at all . It's my fault . please ignore my previous comments . Your current change for this serials is good enough.

Regards
Shaoyun.liu

From: Deucher, Alexander <[email protected]>
Sent: Friday, February 14, 2025 12:42 PM
To: Liu, Shaoyun <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

Does it matter which pipe we use for these packets?

Alex

________________________________
From: Liu, Shaoyun <[email protected]<mailto:[email protected]>>
Sent: Friday, February 14, 2025 12:36 PM
To: Deucher, Alexander <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Subject: RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

Ok . From MES point of view , we expecting both set_hw_resource and set_hw_resource_1 been called all the time.

From: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Sent: Friday, February 14, 2025 11:53 AM
To: Liu, Shaoyun <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I can add that as a follow up patch as I don't want to change the current behavior to avoid a potential regression. Should we submit both the resource and resource_1 packets all the time?

Thanks,

Alex

________________________________

From: Liu, Shaoyun <[email protected]<mailto:[email protected]>>
Sent: Friday, February 14, 2025 11:45 AM
To: Deucher, Alexander <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Subject: RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I'd suggest remove the enable_uni_mes check, set_hw_resource_1 is always required for gfx12 and up. Especially after add the cleaner_shader_fence_addr there.

Regards
Shaoyun.liu

-----Original Message-----
From: amd-gfx <[email protected]<mailto:[email protected]>> On Behalf Of Alex Deucher
Sent: Friday, February 14, 2025 10:19 AM
To: [email protected]<mailto:[email protected]>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Subject: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 39 +++++++++++++-------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +0 -3
index 8dbab3834d82d..6db88584dd529 100644
@@ -678,9 +678,6 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
 
 static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)  {
-       unsigned int alloc_size = AMDGPU_GPU_PAGE_SIZE;
-       int ret = 0;
-       struct amdgpu_device *adev = mes->adev;
        union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_1_pkt;
 
        memset(&mes_set_hw_res_1_pkt, 0, sizeof(mes_set_hw_res_1_pkt)); @@ -689,17 +686,6 @@ static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)
        mes_set_hw_res_1_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
        mes_set_hw_res_1_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
        mes_set_hw_res_1_pkt.mes_kiq_unmap_timeout = 0xa;
-
-       ret = amdgpu_bo_create_kernel(adev, alloc_size, PAGE_SIZE,
-                               AMDGPU_GEM_DOMAIN_VRAM,
-                               &mes->resource_1,
-                               &mes->resource_1_gpu_addr,
-                               &mes->resource_1_addr);

- if (ret) {
- dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
- return ret;
- }
-

        mes_set_hw_res_1_pkt.cleaner_shader_fence_mc_addr =
                mes->resource_1_gpu_addr;

@@ -1550,6 +1536,20 @@ static int mes_v12_0_sw_init(struct amdgpu_ip_block *ip_block)

                        return r;
        }

+ if (adev->enable_uni_mes) {
+ int ret;
+
+ ret = amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE,

+                                             AMDGPU_GEM_DOMAIN_VRAM,
+                                             &adev->mes.resource_1,
+                                             &adev->mes.resource_1_gpu_addr,
+                                             &adev->mes.resource_1_addr);

+ if (ret) {
+ dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+ return ret;
+ }
+ }
+

        return 0;

}

@@ -1558,6 +1558,11 @@ static int mes_v12_0_sw_fini(struct amdgpu_ip_block *ip_block)

        struct amdgpu_device *adev = ip_block->adev;
        int pipe;

+ if (adev->enable_uni_mes)
+ amdgpu_bo_free_kernel(&adev->mes.resource_1,
+ &adev->mes.resource_1_gpu_addr,
+ &adev->mes.resource_1_addr);
+

        for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
                kfree(adev->mes.mqd_backup[pipe]);

@@ -1786,12 +1791,6 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)

static int mes_v12_0_hw_fini(struct amdgpu_ip_block *ip_block) {
- struct amdgpu_device *adev = ip_block->adev;
-
- if (adev->enable_uni_mes)
- amdgpu_bo_free_kernel(&adev->mes.resource_1,
- &adev->mes.resource_1_gpu_addr,

-                                     &adev->mes.resource_1_addr);
        return 0;

}

--
2.48.1

Reviewed-by Shaoyun.liu
#7 lore raw

Re: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I think I should make it more clear. When mes is been used , no matter its pipe0 or pipe1 , we expected both set_hw_resource and set_hw_resource_1 been called, that's requirement for mes_v12 and later . For none unified mes config, the pipe1 will not use mes, so no mes api is required for pipe1, but for pipe0, it's still the same requirement.

Regards
Shaoyun.liu

Get Outlook for iOS<https://aka.ms/o0ukef>
________________________________
From: Liu, Shaoyun
Sent: Friday, February 14, 2025 12:46:27 PM
To: Deucher, Alexander <[email protected]>; [email protected] <[email protected]>
Subject: RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

Oh, you right. It’s only for unified MES , for none-unified , it will still use the kiq from CP directly on pipe1 . So there is no MES API for it at all . It’s my fault . please ignore my previous comments . Your current change for this serials is good enough.

Regards

Shaoyun.liu

From: Deucher, Alexander <[email protected]>
Sent: Friday, February 14, 2025 12:42 PM
To: Liu, Shaoyun <[email protected]>; [email protected]
Subject: Re: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

Does it matter which pipe we use for these packets?

Alex

________________________________

From: Liu, Shaoyun <[email protected]<mailto:[email protected]>>
Sent: Friday, February 14, 2025 12:36 PM
To: Deucher, Alexander <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Subject: RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

Ok . From MES point of view , we expecting both set_hw_resource and set_hw_resource_1 been called all the time.

From: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Sent: Friday, February 14, 2025 11:53 AM
To: Liu, Shaoyun <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>
Subject: Re: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I can add that as a follow up patch as I don't want to change the current behavior to avoid a potential regression. Should we submit both the resource and resource_1 packets all the time?

Thanks,

Alex

________________________________

From: Liu, Shaoyun <[email protected]<mailto:[email protected]>>
Sent: Friday, February 14, 2025 11:45 AM
To: Deucher, Alexander <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Subject: RE: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

[AMD Official Use Only - AMD Internal Distribution Only]

I'd suggest remove the enable_uni_mes check, set_hw_resource_1 is always required for gfx12 and up. Especially after add the cleaner_shader_fence_addr there.

Regards
Shaoyun.liu

-----Original Message-----
From: amd-gfx <[email protected]<mailto:[email protected]>> On Behalf Of Alex Deucher
Sent: Friday, February 14, 2025 10:19 AM
To: [email protected]<mailto:[email protected]>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>
Subject: [PATCH 2/2] drm/amdgpu/mes12: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v12_0.c | 39 +++++++++++++-------------
 1 file changed, 19 insertions(+), 20 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v12_0.c +0 -3
index 8dbab3834d82d..6db88584dd529 100644
@@ -678,9 +678,6 @@ static int mes_v12_0_misc_op(struct amdgpu_mes *mes,
 
 static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)  {
-       unsigned int alloc_size = AMDGPU_GPU_PAGE_SIZE;
-       int ret = 0;
-       struct amdgpu_device *adev = mes->adev;
        union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_1_pkt;
 
        memset(&mes_set_hw_res_1_pkt, 0, sizeof(mes_set_hw_res_1_pkt)); @@ -689,17 +686,6 @@ static int mes_v12_0_set_hw_resources_1(struct amdgpu_mes *mes, int pipe)
        mes_set_hw_res_1_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
        mes_set_hw_res_1_pkt.header.dwsize = API_FRAME_SIZE_IN_DWORDS;
        mes_set_hw_res_1_pkt.mes_kiq_unmap_timeout = 0xa;
-
-       ret = amdgpu_bo_create_kernel(adev, alloc_size, PAGE_SIZE,
-                               AMDGPU_GEM_DOMAIN_VRAM,
-                               &mes->resource_1,
-                               &mes->resource_1_gpu_addr,
-                               &mes->resource_1_addr);

- if (ret) {
- dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
- return ret;
- }
-

        mes_set_hw_res_1_pkt.cleaner_shader_fence_mc_addr =
                mes->resource_1_gpu_addr;

@@ -1550,6 +1536,20 @@ static int mes_v12_0_sw_init(struct amdgpu_ip_block *ip_block)

                        return r;
        }

+ if (adev->enable_uni_mes) {
+ int ret;
+
+ ret = amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE, PAGE_SIZE,

+                                             AMDGPU_GEM_DOMAIN_VRAM,
+                                             &adev->mes.resource_1,
+                                             &adev->mes.resource_1_gpu_addr,
+                                             &adev->mes.resource_1_addr);

+ if (ret) {
+ dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+ return ret;
+ }
+ }
+

        return 0;

}

@@ -1558,6 +1558,11 @@ static int mes_v12_0_sw_fini(struct amdgpu_ip_block *ip_block)

        struct amdgpu_device *adev = ip_block->adev;
        int pipe;

+ if (adev->enable_uni_mes)
+ amdgpu_bo_free_kernel(&adev->mes.resource_1,
+ &adev->mes.resource_1_gpu_addr,
+ &adev->mes.resource_1_addr);
+

        for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
                kfree(adev->mes.mqd_backup[pipe]);

@@ -1786,12 +1791,6 @@ static int mes_v12_0_hw_init(struct amdgpu_ip_block *ip_block)

static int mes_v12_0_hw_fini(struct amdgpu_ip_block *ip_block) {
- struct amdgpu_device *adev = ip_block->adev;
-
- if (adev->enable_uni_mes)
- amdgpu_bo_free_kernel(&adev->mes.resource_1,
- &adev->mes.resource_1_gpu_addr,

-                                     &adev->mes.resource_1_addr);
        return 0;

}

--
2.48.1

Reviewed-by Shaoyun.liu on v1 1/2
#8 lore raw
In reply to Alex Deucher

[AMD Official Use Only - AMD Internal Distribution Only]

Looks good to me .

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Friday, February 14, 2025 10:19 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/mes11: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 52 +++++++++++++-------------
 1 file changed, 26 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +1 -0
index 26af0af718b5e..530371e6a7aee 100644
@@ -64,6 +64,7 @@ static int mes_v11_0_kiq_hw_fini(struct amdgpu_device *adev);
 
 #define MES_EOP_SIZE   2048
 #define GFX_MES_DRAM_SIZE      0x80000
+#define MES11_HW_RESOURCE_1_SIZE (128 * AMDGPU_GPU_PAGE_SIZE)
 
 static void mes_v11_0_ring_set_wptr(struct amdgpu_ring *ring)  { @@ -743,11 +744,6 @@ 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) {

-       unsigned int hw_rsrc_size = 128 * AMDGPU_GPU_PAGE_SIZE;
-       /* add a page for the cleaner shader fence */
-       unsigned int alloc_size = hw_rsrc_size + AMDGPU_GPU_PAGE_SIZE;
-       int ret = 0;
-       struct amdgpu_device *adev = mes->adev;
        union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_pkt;
        memset(&mes_set_hw_res_pkt, 0, sizeof(mes_set_hw_res_pkt));

@@ -755,21 +751,10 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes)

        mes_set_hw_res_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
        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, alloc_size, PAGE_SIZE,
-                               AMDGPU_GEM_DOMAIN_VRAM,
-                               &mes->resource_1,
-                               &mes->resource_1_gpu_addr,
-                               &mes->resource_1_addr);

- if (ret) {
- dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
- return ret;
- }
-

        mes_set_hw_res_pkt.mes_info_ctx_mc_addr = mes->resource_1_gpu_addr;

- mes_set_hw_res_pkt.mes_info_ctx_size = hw_rsrc_size;
+ mes_set_hw_res_pkt.mes_info_ctx_size = MES11_HW_RESOURCE_1_SIZE;
mes_set_hw_res_pkt.cleaner_shader_fence_mc_addr =
- mes->resource_1_gpu_addr + hw_rsrc_size;
+ mes->resource_1_gpu_addr + MES11_HW_RESOURCE_1_SIZE;

        return mes_v11_0_submit_pkt_and_poll_completion(mes,
                        &mes_set_hw_res_pkt, sizeof(mes_set_hw_res_pkt), @@ -1442,6 +1427,23 @@ static int mes_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
        if (r)
                return r;

+ if (amdgpu_sriov_is_mes_info_enable(adev) ||
+ adev->gfx.enable_cleaner_shader) {
+ int ret;
+
+ ret = amdgpu_bo_create_kernel(adev,

+                                             MES11_HW_RESOURCE_1_SIZE + AMDGPU_GPU_PAGE_SIZE,
+                                             PAGE_SIZE,
+                                             AMDGPU_GEM_DOMAIN_VRAM,
+                                             &adev->mes.resource_1,
+                                             &adev->mes.resource_1_gpu_addr,
+                                             &adev->mes.resource_1_addr);

+ if (ret) {
+ dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+ return ret;
+ }
+ }
+

        return 0;

}

@@ -1450,6 +1452,12 @@ static int mes_v11_0_sw_fini(struct amdgpu_ip_block *ip_block)

        struct amdgpu_device *adev = ip_block->adev;
        int pipe;

+ 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);
+ }
+

        for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
                kfree(adev->mes.mqd_backup[pipe]);

@@ -1670,14 +1678,6 @@ 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) ||
- adev->gfx.enable_cleaner_shader) {
- amdgpu_bo_free_kernel(&adev->mes.resource_1, &adev->mes.resource_1_gpu_addr,
- &adev->mes.resource_1_addr);
- }
-

        return 0;

}

--
2.48.1

#9 lore raw
Quoted 5 lines · Shaoyun

[AMD Official Use Only - AMD Internal Distribution Only]

Looks good to me .

Thanks, is this for the whole series or just this patch?

Alex

Quoted 113 lines

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Alex Deucher
Sent: Friday, February 14, 2025 10:19 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: [PATCH 1/2] drm/amdgpu/mes11: allocate hw_resource_1 buffer once

Allocate the buffer at sw init time so we don't alloc and free it for every suspend/resume or reset cycle.

---
 drivers/gpu/drm/amd/amdgpu/mes_v11_0.c | 52 +++++++++++++-------------
 1 file changed, 26 insertions(+), 26 deletions(-)
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +1 -0
index 26af0af718b5e..530371e6a7aee 100644
@@ -64,6 +64,7 @@ static int mes_v11_0_kiq_hw_fini(struct amdgpu_device *adev);
 
 #define MES_EOP_SIZE   2048
 #define GFX_MES_DRAM_SIZE      0x80000
+#define MES11_HW_RESOURCE_1_SIZE (128 * AMDGPU_GPU_PAGE_SIZE)
 
 static void mes_v11_0_ring_set_wptr(struct amdgpu_ring *ring)  { @@ -743,11 +744,6 @@ 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) {

drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +2 -18
-       unsigned int hw_rsrc_size = 128 * AMDGPU_GPU_PAGE_SIZE;
-       /* add a page for the cleaner shader fence */
-       unsigned int alloc_size = hw_rsrc_size + AMDGPU_GPU_PAGE_SIZE;
-       int ret = 0;
-       struct amdgpu_device *adev = mes->adev;
        union MESAPI_SET_HW_RESOURCES_1 mes_set_hw_res_pkt;
        memset(&mes_set_hw_res_pkt, 0, sizeof(mes_set_hw_res_pkt));
@@ -755,21 +751,10 @@ static int mes_v11_0_set_hw_resources_1(struct amdgpu_mes *mes)
        mes_set_hw_res_pkt.header.opcode = MES_SCH_API_SET_HW_RSRC_1;
        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, alloc_size, PAGE_SIZE,
-                               AMDGPU_GEM_DOMAIN_VRAM,
-                               &mes->resource_1,
-                               &mes->resource_1_gpu_addr,
-                               &mes->resource_1_addr);
-       if (ret) {
-               dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
-               return ret;
-       }
-
        mes_set_hw_res_pkt.mes_info_ctx_mc_addr = mes->resource_1_gpu_addr;
-       mes_set_hw_res_pkt.mes_info_ctx_size = hw_rsrc_size;
+       mes_set_hw_res_pkt.mes_info_ctx_size = MES11_HW_RESOURCE_1_SIZE;
        mes_set_hw_res_pkt.cleaner_shader_fence_mc_addr =
-               mes->resource_1_gpu_addr + hw_rsrc_size;
+               mes->resource_1_gpu_addr + MES11_HW_RESOURCE_1_SIZE;
 
        return mes_v11_0_submit_pkt_and_poll_completion(mes,
                        &mes_set_hw_res_pkt, sizeof(mes_set_hw_res_pkt), @@ -1442,6 +1427,23 @@ static int mes_v11_0_sw_init(struct amdgpu_ip_block *ip_block)
        if (r)
                return r;
drivers/gpu/drm/amd/amdgpu/mes_v11_0.c +23 -9
+       if (amdgpu_sriov_is_mes_info_enable(adev) ||
+           adev->gfx.enable_cleaner_shader) {
+               int ret;
+
+               ret = amdgpu_bo_create_kernel(adev,
+                                             MES11_HW_RESOURCE_1_SIZE + AMDGPU_GPU_PAGE_SIZE,
+                                             PAGE_SIZE,
+                                             AMDGPU_GEM_DOMAIN_VRAM,
+                                             &adev->mes.resource_1,
+                                             &adev->mes.resource_1_gpu_addr,
+                                             &adev->mes.resource_1_addr);
+               if (ret) {
+                       dev_err(adev->dev, "(%d) failed to create mes resource_1 bo\n", ret);
+                       return ret;
+               }
+       }
+
        return 0;
 }
@@ -1450,6 +1452,12 @@ static int mes_v11_0_sw_fini(struct amdgpu_ip_block *ip_block)
        struct amdgpu_device *adev = ip_block->adev;
        int pipe;
 
+       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);
+       }
+
        for (pipe = 0; pipe < AMDGPU_MAX_MES_PIPES; pipe++) {
                kfree(adev->mes.mqd_backup[pipe]);
 
@@ -1670,14 +1678,6 @@ 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) ||
-           adev->gfx.enable_cleaner_shader) {
-               amdgpu_bo_free_kernel(&adev->mes.resource_1, &adev->mes.resource_1_gpu_addr,
-                                     &adev->mes.resource_1_addr);
-       }
-
        return 0;
 }
 
--

2.48.1