Skip to contentSkip to conversation

drm/amdgpu: Store CU info from all XCCs for GFX v9.4.3

PATCH In review Mukul Joshi 2 participants 10 messages Sep 6, 2023 – Sep 7, 2023

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

PATCH v2 1/4 drm/amdgpu: Store CU info from all XCCs for GFX v9.4.3

Currently, we store CU info only for a single XCC assuming that it is the same for all XCCs. However, that may not be true. As a result, store CU info for all XCCs. This info is later used for CU masking.

---
v1->v2:
- Incorporate Felix's review comments.

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    |  2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  2 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  4 +-
 drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c       | 76 +++++++++----------
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c         |  3 +-
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c  |  8 +-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c     | 11 ++-
 .../gpu/drm/amd/include/kgd_kfd_interface.h   |  6 +-
 14 files changed, 60 insertions(+), 65 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +1 -1
index cdf6087706aa..25d5fda5b243 100644
@@ -478,7 +478,7 @@ void amdgpu_amdkfd_get_cu_info(struct amdgpu_device *adev, struct kfd_cu_info *c
 	cu_info->cu_active_number = acu_info.number;
 	cu_info->cu_ao_mask = acu_info.ao_cu_mask;
 	memcpy(&cu_info->cu_bitmap[0], &acu_info.bitmap[0],
-	       sizeof(acu_info.bitmap));
+	       sizeof(cu_info->cu_bitmap));
 	cu_info->num_shader_engines = adev->gfx.config.max_shader_engines;
 	cu_info->num_shader_arrays_per_engine = adev->gfx.config.max_sh_per_se;
 	cu_info->num_cu_per_sh = adev->gfx.config.max_cu_per_sh;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +2 -1
index 395c1768b9fc..0ca95c4d4bfb 100644
@@ -43,6 +43,7 @@
 #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
 
 #define AMDGPU_MAX_GC_INSTANCES		8
+#define KGD_MAX_QUEUES			128
 
 #define AMDGPU_MAX_GFX_QUEUES KGD_MAX_QUEUES
 #define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
@@ -257,7 +258,7 @@ struct amdgpu_cu_info {
 	uint32_t number;
 	uint32_t ao_cu_mask;
 	uint32_t ao_cu_bitmap[4][4];
-	uint32_t bitmap[4][4];
+	uint32_t bitmap[AMDGPU_MAX_GC_INSTANCES][4][4];
 };
 
 struct amdgpu_gfx_ras {
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +1 -1
index 3a48bec10aea..d462b36adf4b 100644
@@ -850,7 +850,7 @@ int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
 		memcpy(&dev_info->cu_ao_bitmap[0], &adev->gfx.cu_info.ao_cu_bitmap[0],
 		       sizeof(adev->gfx.cu_info.ao_cu_bitmap));
 		memcpy(&dev_info->cu_bitmap[0], &adev->gfx.cu_info.bitmap[0],
-		       sizeof(adev->gfx.cu_info.bitmap));
+		       sizeof(dev_info->cu_bitmap));
 		dev_info->vram_type = adev->gmc.vram_type;
 		dev_info->vram_bit_width = adev->gmc.vram_width;
 		dev_info->vce_harvest_config = adev->vce.harvest_config;
drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c +1 -1
index 6ccde07ed63e..62329a822022 100644
@@ -9442,7 +9442,7 @@ static int gfx_v10_0_get_cu_info(struct amdgpu_device *adev,
 				gfx_v10_0_set_user_wgp_inactive_bitmap_per_sh(
 					adev, disable_masks[i * 2 + j]);
 			bitmap = gfx_v10_0_get_cu_active_bitmap_per_sh(adev);
-			cu_info->bitmap[i][j] = bitmap;
+			cu_info->bitmap[0][i][j] = bitmap;
 
 			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k++) {
 				if (bitmap & mask) {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +1 -1
index 337ed771605f..39c434ca0dad 100644
@@ -6392,7 +6392,7 @@ static int gfx_v11_0_get_cu_info(struct amdgpu_device *adev,
 			 *    SE6: {SH0,SH1} --> {bitmap[2][2], bitmap[2][3]}
 			 *    SE7: {SH0,SH1} --> {bitmap[3][2], bitmap[3][3]}
 			 */
-			cu_info->bitmap[i % 4][j + (i / 4) * 2] = bitmap;
+			cu_info->bitmap[0][i % 4][j + (i / 4) * 2] = bitmap;
 
 			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k++) {
 				if (bitmap & mask)
drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c +1 -1
index da6caff78c22..34f9211b2679 100644
@@ -3577,7 +3577,7 @@ static void gfx_v6_0_get_cu_info(struct amdgpu_device *adev)
 				gfx_v6_0_set_user_cu_inactive_bitmap(
 					adev, disable_masks[i * 2 + j]);
 			bitmap = gfx_v6_0_get_cu_enabled(adev);
-			cu_info->bitmap[i][j] = bitmap;
+			cu_info->bitmap[0][i][j] = bitmap;
 
 			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k++) {
 				if (bitmap & mask) {
drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c +1 -1
index 90b034b173c1..c2faf6b4c2fc 100644
@@ -5119,7 +5119,7 @@ static void gfx_v7_0_get_cu_info(struct amdgpu_device *adev)
 				gfx_v7_0_set_user_cu_inactive_bitmap(
 					adev, disable_masks[i * 2 + j]);
 			bitmap = gfx_v7_0_get_cu_active_bitmap(adev);
-			cu_info->bitmap[i][j] = bitmap;
+			cu_info->bitmap[0][i][j] = bitmap;
 
 			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k++) {
 				if (bitmap & mask) {
drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c +1 -1
index 51c1745c8369..885ebd703260 100644
@@ -7121,7 +7121,7 @@ static void gfx_v8_0_get_cu_info(struct amdgpu_device *adev)
 				gfx_v8_0_set_user_cu_inactive_bitmap(
 					adev, disable_masks[i * 2 + j]);
 			bitmap = gfx_v8_0_get_cu_active_bitmap(adev);
-			cu_info->bitmap[i][j] = bitmap;
+			cu_info->bitmap[0][i][j] = bitmap;
 
 			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k ++) {
 				if (bitmap & mask) {
drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c +2 -2
index 5c85ac34360f..f99a3a6bfd91 100644
@@ -1499,7 +1499,7 @@ static void gfx_v9_0_init_always_on_cu_mask(struct amdgpu_device *adev)
 			amdgpu_gfx_select_se_sh(adev, i, j, 0xffffffff, 0);
 
 			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k ++) {
-				if (cu_info->bitmap[i][j] & mask) {
+				if (cu_info->bitmap[0][i][j] & mask) {
 					if (counter == pg_always_on_cu_num)
 						WREG32_SOC15(GC, 0, mmRLC_PG_ALWAYS_ON_CU_MASK, cu_bitmap);
 					if (counter < always_on_cu_num)
@@ -7233,7 +7233,7 @@ static int gfx_v9_0_get_cu_info(struct amdgpu_device *adev,
 			 *    SE6,SH0 --> bitmap[2][1]
 			 *    SE7,SH0 --> bitmap[3][1]
 			 */
-			cu_info->bitmap[i % 4][j + i / 4] = bitmap;
+			cu_info->bitmap[0][i % 4][j + i / 4] = bitmap;
 
 			for (k = 0; k < adev->gfx.config.max_cu_per_sh; k ++) {
 				if (bitmap & mask) {
drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c +34 -42

109 lines not on this page · raw message

drivers/gpu/drm/amd/amdkfd/kfd_crat.c +2 -1
index 2e9612cf56ae..950810bb5c71 100644
@@ -2088,7 +2088,8 @@ static int kfd_create_vcrat_image_gpu(void *pcrat_image,
 
 	amdgpu_amdkfd_get_cu_info(kdev->adev, &cu_info);
 	cu->num_simd_per_cu = cu_info.simd_per_cu;
-	cu->num_simd_cores = cu_info.simd_per_cu * cu_info.cu_active_number;
+	cu->num_simd_cores = cu_info.simd_per_cu *
+			(cu_info.cu_active_number / kdev->kfd->num_nodes);
 	cu->max_waves_simd = cu_info.max_waves_per_simd;
 
 	cu->wave_front_size = cu_info.wave_front_size;
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c +5 -3
index d01bb57733b3..763966236658 100644
@@ -104,11 +104,13 @@ void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
 	bool wgp_mode_req = KFD_GC_VERSION(mm->dev) >= IP_VERSION(10, 0, 0);
 	uint32_t en_mask = wgp_mode_req ? 0x3 : 0x1;
 	int i, se, sh, cu, cu_bitmap_sh_mul, inc = wgp_mode_req ? 2 : 1;
+	uint32_t cu_active_per_node;
 
 	amdgpu_amdkfd_get_cu_info(mm->dev->adev, &cu_info);
 
-	if (cu_mask_count > cu_info.cu_active_number)
-		cu_mask_count = cu_info.cu_active_number;
+	cu_active_per_node = cu_info.cu_active_number / mm->dev->kfd->num_nodes;
+	if (cu_mask_count > cu_active_per_node)
+		cu_mask_count = cu_active_per_node;
 
 	/* Exceeding these bounds corrupts the stack and indicates a coding error.
 	 * Returning with no CU's enabled will hang the queue, which should be
@@ -141,7 +143,7 @@ void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
 	for (se = 0; se < cu_info.num_shader_engines; se++)
 		for (sh = 0; sh < cu_info.num_shader_arrays_per_engine; sh++)
 			cu_per_sh[se][sh] = hweight32(
-				cu_info.cu_bitmap[se % 4][sh + (se / 4) * cu_bitmap_sh_mul]);
+				cu_info.cu_bitmap[0][se % 4][sh + (se / 4) * cu_bitmap_sh_mul]);
 
 	/* Symmetrically map cu_mask to all SEs & SHs:
 	 * se_mask programs up to 2 SH in the upper and lower 16 bits.
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +5 -6
index ff98fded9534..c54795682dfb 100644
@@ -450,8 +450,7 @@ static ssize_t node_show(struct kobject *kobj, struct attribute *attr,
 	sysfs_show_32bit_prop(buffer, offs, "cpu_cores_count",
 			      dev->node_props.cpu_cores_count);
 	sysfs_show_32bit_prop(buffer, offs, "simd_count",
-			      dev->gpu ? (dev->node_props.simd_count *
-					  NUM_XCC(dev->gpu->xcc_mask)) : 0);
+			      dev->gpu ? dev->node_props.simd_count : 0);
 	sysfs_show_32bit_prop(buffer, offs, "mem_banks_count",
 			      dev->node_props.mem_banks_count);
 	sysfs_show_32bit_prop(buffer, offs, "caches_count",
@@ -1604,7 +1603,7 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
 	int i, j, k;
 	struct kfd_cache_properties *pcache = NULL;
 
-	cu_sibling_map_mask = cu_info->cu_bitmap[0][0];
+	cu_sibling_map_mask = cu_info->cu_bitmap[0][0][0];
 	cu_sibling_map_mask &=
 		((1 << pcache_info[cache_type].num_cu_shared) - 1);
 	first_active_cu = ffs(cu_sibling_map_mask);
@@ -1647,7 +1646,7 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
 				pcache->sibling_map[k+3] = (uint8_t)((cu_sibling_map_mask >> 24) & 0xFF);
 				k += 4;
 
-				cu_sibling_map_mask = cu_info->cu_bitmap[i % 4][j + i / 4];
+				cu_sibling_map_mask = cu_info->cu_bitmap[0][i % 4][j + i / 4];
 				cu_sibling_map_mask &= ((1 << pcache_info[cache_type].num_cu_shared) - 1);
 			}
 		}
@@ -1708,8 +1707,8 @@ static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct
 					for (k = 0; k < pcu_info->num_cu_per_sh; k += pcache_info[ct].num_cu_shared) {
 
 						ret = fill_in_l1_pcache(&props_ext, pcache_info, pcu_info,
-										pcu_info->cu_bitmap[i % 4][j + i / 4], ct,
-										cu_processor_id, k);
+									pcu_info->cu_bitmap[0][i % 4][j + i / 4], ct,
+									cu_processor_id, k);
 
 						if (ret < 0)
 							break;
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +3 -3
index f3f40dbb8ff7..3b5a56585c4b 100644
@@ -31,12 +31,12 @@
 #include <linux/types.h>
 #include <linux/bitmap.h>
 #include <linux/dma-fence.h>
+#include "amdgpu_irq.h"
+#include "amdgpu_gfx.h"
 
 struct pci_dev;
 struct amdgpu_device;
 
-#define KGD_MAX_QUEUES 128
-
 struct kfd_dev;
 struct kgd_mem;
 
@@ -68,7 +68,7 @@ struct kfd_cu_info {
 	uint32_t wave_front_size;
 	uint32_t max_scratch_slots_per_cu;
 	uint32_t lds_size;
-	uint32_t cu_bitmap[4][4];
+	uint32_t cu_bitmap[AMDGPU_MAX_GC_INSTANCES][4][4];
 };
 
 /* For getting GPU local memory information from KGD */
Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 2/4 drm/amdkfd: Update cache info reporting for GFX v9.4.3

Update cache info reporting in sysfs to report the correct number of CUs and associated cache information based on different spatial partitioning modes.

---
v1->v2:
- Revert the change in kfd_crat.c
- Add a comment to not change value of CRAT_SIBLINGMAP_SIZE.

 drivers/gpu/drm/amd/amdkfd/kfd_crat.h     |  4 ++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 82 +++++++++++++----------
 drivers/gpu/drm/amd/amdkfd/kfd_topology.h |  2 +-
 3 files changed, 51 insertions(+), 37 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +4 -0
index 387a8ef49385..74c2d7a0d628 100644
@@ -79,6 +79,10 @@ struct crat_header {
 #define CRAT_SUBTYPE_IOLINK_AFFINITY		5
 #define CRAT_SUBTYPE_MAX			6
 
+/*
+ * Do not change the value of CRAT_SIBLINGMAP_SIZE from 32
+ * as it breaks the ABI.
+ */
 #define CRAT_SIBLINGMAP_SIZE	32
 
 /*
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +46 -36

120 lines not on this page · raw message

drivers/gpu/drm/amd/amdkfd/kfd_topology.h +1 -1
index dea32a9e5506..27386ce9a021 100644
@@ -89,7 +89,7 @@ struct kfd_mem_properties {
 	struct attribute	attr;
 };
 
-#define CACHE_SIBLINGMAP_SIZE 64
+#define CACHE_SIBLINGMAP_SIZE 128
 
 struct kfd_cache_properties {
 	struct list_head	list;
Signature · 1 line
2.35.1
maintainer Reviewed-by on v2 2/4
#2 lore raw

Re: [PATCHv2 2/4] drm/amdkfd: Update cache info reporting for GFX v9.4.3

Quoted 69 lines · Mukul Joshi

Update cache info reporting in sysfs to report the correct number of CUs and associated cache information based on different spatial partitioning modes.

---
v1->v2:
- Revert the change in kfd_crat.c
- Add a comment to not change value of CRAT_SIBLINGMAP_SIZE.

  drivers/gpu/drm/amd/amdkfd/kfd_crat.h     |  4 ++
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 82 +++++++++++++----------
  drivers/gpu/drm/amd/amdkfd/kfd_topology.h |  2 +-
  3 files changed, 51 insertions(+), 37 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +4 -0
index 387a8ef49385..74c2d7a0d628 100644
@@ -79,6 +79,10 @@ struct crat_header {
  #define CRAT_SUBTYPE_IOLINK_AFFINITY		5
  #define CRAT_SUBTYPE_MAX			6
 
+/*
+ * Do not change the value of CRAT_SIBLINGMAP_SIZE from 32
+ * as it breaks the ABI.
+ */
  #define CRAT_SIBLINGMAP_SIZE	32
 
  /*
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +6 -13
index c54795682dfb..b98cc7930e4c 100644
@@ -1596,14 +1596,17 @@ static int fill_in_l1_pcache(struct kfd_cache_properties **props_ext,
  static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
  				struct kfd_gpu_cache_info *pcache_info,
  				struct kfd_cu_info *cu_info,
-				int cache_type, unsigned int cu_processor_id)
+				int cache_type, unsigned int cu_processor_id,
+				struct kfd_node *knode)
  {
  	unsigned int cu_sibling_map_mask;
  	int first_active_cu;
-	int i, j, k;
+	int i, j, k, xcc, start, end;
  	struct kfd_cache_properties *pcache = NULL;
 
-	cu_sibling_map_mask = cu_info->cu_bitmap[0][0][0];
+	start = ffs(knode->xcc_mask) - 1;
+	end = start + NUM_XCC(knode->xcc_mask);
+	cu_sibling_map_mask = cu_info->cu_bitmap[start][0][0];
  	cu_sibling_map_mask &=
  		((1 << pcache_info[cache_type].num_cu_shared) - 1);
  	first_active_cu = ffs(cu_sibling_map_mask);
@@ -1638,16 +1641,18 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
  		cu_sibling_map_mask = cu_sibling_map_mask >> (first_active_cu - 1);
  		k = 0;
 
-		for (i = 0; i < cu_info->num_shader_engines; i++) {
-			for (j = 0; j < cu_info->num_shader_arrays_per_engine; j++) {
-				pcache->sibling_map[k] = (uint8_t)(cu_sibling_map_mask & 0xFF);
-				pcache->sibling_map[k+1] = (uint8_t)((cu_sibling_map_mask >> 8) & 0xFF);
-				pcache->sibling_map[k+2] = (uint8_t)((cu_sibling_map_mask >> 16) & 0xFF);
-				pcache->sibling_map[k+3] = (uint8_t)((cu_sibling_map_mask >> 24) & 0xFF);
-				k += 4;
-
-				cu_sibling_map_mask = cu_info->cu_bitmap[0][i % 4][j + i / 4];
-				cu_sibling_map_mask &= ((1 << pcache_info[cache_type].num_cu_shared) - 1);

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext, · line 1653

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +10 -0
+		for (xcc = start; xcc < end; xcc++) {
+			for (i = 0; i < cu_info->num_shader_engines; i++) {
+				for (j = 0; j < cu_info->num_shader_arrays_per_engine; j++) {
+					pcache->sibling_map[k] = (uint8_t)(cu_sibling_map_mask & 0xFF);
+					pcache->sibling_map[k+1] = (uint8_t)((cu_sibling_map_mask >> 8) & 0xFF);
+					pcache->sibling_map[k+2] = (uint8_t)((cu_sibling_map_mask >> 16) & 0xFF);
+					pcache->sibling_map[k+3] = (uint8_t)((cu_sibling_map_mask >> 24) & 0xFF);
+					k += 4;
+
+					cu_sibling_map_mask = cu_info->cu_bitmap[start][i % 4][j + i / 4];

Shouldn't this use "xcc" as index instead of "start"?

Other than that, this patch is

P.S.: This whole function looks suspicious to me the way it exposes active/inactive CUs to user mode. I think user mode only wants to count active CUs in the sibling mask because it has no other information about inactive CUs. And reading the cu_info into cu_sibling_map_mask and then only using it in the next loop iteration is probably also wrong. It basically throws away cu_info from the last xcc,SE,SA. Or maybe I just don't understand what this function is trying to do.

Quoted 92 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +30 -23
+					cu_sibling_map_mask &= ((1 << pcache_info[cache_type].num_cu_shared) - 1);
+				}
  			}
  		}
  		pcache->sibling_map_size = k;
@@ -1665,7 +1670,7 @@ static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
  static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct kfd_node *kdev)
  {
  	struct kfd_gpu_cache_info *pcache_info = NULL;
-	int i, j, k;
+	int i, j, k, xcc, start, end;
  	int ct = 0;
  	unsigned int cu_processor_id;
  	int ret;
@@ -1699,37 +1704,42 @@ static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct
  	 *			then it will consider only one CU from
  	 *			the shared unit
  	 */
+	start = ffs(kdev->xcc_mask) - 1;
+	end = start + NUM_XCC(kdev->xcc_mask);
+
  	for (ct = 0; ct < num_of_cache_types; ct++) {
  		cu_processor_id = gpu_processor_id;
  		if (pcache_info[ct].cache_level == 1) {
-			for (i = 0; i < pcu_info->num_shader_engines; i++) {
-				for (j = 0; j < pcu_info->num_shader_arrays_per_engine; j++) {
-					for (k = 0; k < pcu_info->num_cu_per_sh; k += pcache_info[ct].num_cu_shared) {
-
-						ret = fill_in_l1_pcache(&props_ext, pcache_info, pcu_info,
-									pcu_info->cu_bitmap[0][i % 4][j + i / 4], ct,
-									cu_processor_id, k);
-
-						if (ret < 0)
-							break;
-
-						if (!ret) {
-							num_of_entries++;
-							list_add_tail(&props_ext->list, &dev->cache_props);
+			for (xcc = start; xcc < end; xcc++) {
+				for (i = 0; i < pcu_info->num_shader_engines; i++) {
+					for (j = 0; j < pcu_info->num_shader_arrays_per_engine; j++) {
+						for (k = 0; k < pcu_info->num_cu_per_sh; k += pcache_info[ct].num_cu_shared) {
+
+							ret = fill_in_l1_pcache(&props_ext, pcache_info, pcu_info,
+										pcu_info->cu_bitmap[xcc][i % 4][j + i / 4], ct,
+										cu_processor_id, k);
+
+							if (ret < 0)
+								break;
+
+							if (!ret) {
+								num_of_entries++;
+								list_add_tail(&props_ext->list, &dev->cache_props);
+							}
+
+							/* Move to next CU block */
+							num_cu_shared = ((k + pcache_info[ct].num_cu_shared) <=
+								pcu_info->num_cu_per_sh) ?
+								pcache_info[ct].num_cu_shared :
+								(pcu_info->num_cu_per_sh - k);
+							cu_processor_id += num_cu_shared;
  						}
-
-						/* Move to next CU block */
-						num_cu_shared = ((k + pcache_info[ct].num_cu_shared) <=
-							pcu_info->num_cu_per_sh) ?
-							pcache_info[ct].num_cu_shared :
-							(pcu_info->num_cu_per_sh - k);
-						cu_processor_id += num_cu_shared;
  					}
  				}
  			}
  		} else {
  			ret = fill_in_l2_l3_pcache(&props_ext, pcache_info,
-								pcu_info, ct, cu_processor_id);
+					pcu_info, ct, cu_processor_id, kdev);
 
  			if (ret < 0)
  				break;
drivers/gpu/drm/amd/amdkfd/kfd_topology.h +1 -1
index dea32a9e5506..27386ce9a021 100644
@@ -89,7 +89,7 @@ struct kfd_mem_properties {
  	struct attribute	attr;
  };
 
-#define CACHE_SIBLINGMAP_SIZE 64
+#define CACHE_SIBLINGMAP_SIZE 128
 
  struct kfd_cache_properties {
  	struct list_head	list;
#3 lore raw

RE: [PATCHv2 2/4] drm/amdkfd: Update cache info reporting for GFX v9.4.3

[AMD Official Use Only - General]

Quoted 102 lines

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Thursday, September 7, 2023 4:51 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Subject: Re: [PATCHv2 2/4] drm/amdkfd: Update cache info reporting for GFX v9.4.3

Quoted 4 lines · Mukul Joshi

Update cache info reporting in sysfs to report the correct number of CUs and associated cache information based on different spatial partitioning modes.

Quoted 8 lines

---
v1->v2:
- Revert the change in kfd_crat.c
- Add a comment to not change value of CRAT_SIBLINGMAP_SIZE.

  drivers/gpu/drm/amd/amdkfd/kfd_crat.h     |  4 ++
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 82 +++++++++++++-------

---

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l1_pcache(struct

Quoted 25 lines
  drivers/gpu/drm/amd/amdkfd/kfd_topology.h |  2 +-
  3 files changed, 51 insertions(+), 37 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +4 -0
index 387a8ef49385..74c2d7a0d628 100644
@@ -79,6 +79,10 @@ struct crat_header {
  #define CRAT_SUBTYPE_IOLINK_AFFINITY              5
  #define CRAT_SUBTYPE_MAX                  6
 
+/*
+ * Do not change the value of CRAT_SIBLINGMAP_SIZE from 32
+ * as it breaks the ABI.
+ */
  #define CRAT_SIBLINGMAP_SIZE      32
 
  /*
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
index c54795682dfb..b98cc7930e4c 100644
@@ -1596,14 +1596,17 @@ static int fill_in_l1_pcache(struct

kfd_cache_properties **props_ext,

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2 -2
  static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
                            struct kfd_gpu_cache_info *pcache_info,
                            struct kfd_cu_info *cu_info,
-                           int cache_type, unsigned int cu_processor_id)
+                           int cache_type, unsigned int cu_processor_id,
+                           struct kfd_node *knode)
  {
    unsigned int cu_sibling_map_mask;
    int first_active_cu;
-   int i, j, k;

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l1_pcache(struct kfd_cache_properties **props_ext,

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +4 -1
+   int i, j, k, xcc, start, end;
    struct kfd_cache_properties *pcache = NULL;
 
-   cu_sibling_map_mask = cu_info->cu_bitmap[0][0][0];
+   start = ffs(knode->xcc_mask) - 1;
+   end = start + NUM_XCC(knode->xcc_mask);
+   cu_sibling_map_mask = cu_info->cu_bitmap[start][0][0];
    cu_sibling_map_mask &=
            ((1 << pcache_info[cache_type].num_cu_shared) - 1);
    first_active_cu = ffs(cu_sibling_map_mask); @@ -1638,16 +1641,18

@@

Quoted 2 lines

static int fill_in_l2_l3_pcache(struct kfd_cache_properties **props_ext,
cu_sibling_map_mask = cu_sibling_map_mask >>

(first_active_cu - 1);

Quoted 6 lines
            k = 0;
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -2
-           for (i = 0; i < cu_info->num_shader_engines; i++) {
-                   for (j = 0; j < cu_info-

num_shader_arrays_per_engine; j++) {
- pcache->sibling_map[k] =

(uint8_t)(cu_sibling_map_mask & 0xFF);

Quoted 1 line

- pcache->sibling_map[k+1] =

(uint8_t)((cu_sibling_map_mask >> 8) & 0xFF);

Quoted 1 line

- pcache->sibling_map[k+2] =

(uint8_t)((cu_sibling_map_mask >> 16) & 0xFF);

Quoted 1 line

- pcache->sibling_map[k+3] =

(uint8_t)((cu_sibling_map_mask >> 24) & 0xFF);

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -3
-                           k += 4;
-
-                           cu_sibling_map_mask = cu_info-

cu_bitmap[0][i % 4][j + i / 4];
- cu_sibling_map_mask &= ((1 <<

pcache_info[cache_type].num_cu_shared) - 1);

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -0
+           for (xcc = start; xcc < end; xcc++) {
+                   for (i = 0; i < cu_info->num_shader_engines; i++) {
+                           for (j = 0; j < cu_info-

num_shader_arrays_per_engine; j++) {
+ pcache->sibling_map[k] =

(uint8_t)(cu_sibling_map_mask & 0xFF);

Quoted 1 line

+ pcache->sibling_map[k+1] =

(uint8_t)((cu_sibling_map_mask >> 8) & 0xFF);

Quoted 1 line

+ pcache->sibling_map[k+2] =

(uint8_t)((cu_sibling_map_mask >> 16) & 0xFF);

Quoted 1 line

+ pcache->sibling_map[k+3] =

Quoted 9 lines

(uint8_t)((cu_sibling_map_mask >> 24) & 0xFF);

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -0
+                                   k += 4;
+
+                                   cu_sibling_map_mask = cu_info-

cu_bitmap[start][i % 4][j + i /
+4];

Shouldn't this use "xcc" as index instead of "start"?

Yes that’s correct. Thanks for the catch. I will fix this before committing.

Quoted 4 lines

Other than that, this patch is

Quoted 8 lines

P.S.: This whole function looks suspicious to me the way it exposes active/inactive CUs to user mode. I think user mode only wants to count active CUs in the sibling mask because it has no other information about inactive CUs. And reading the cu_info into cu_sibling_map_mask and then only using it in the next loop iteration is probably also wrong. It basically throws away cu_info from the last xcc,SE,SA. Or maybe I just don't understand what this function is trying to do.

Yes the function is a bit convoluted to understand. It starts with the following code before entering the loop.
cu_sibling_map_mask = cu_info->cu_bitmap[start][0][0];
cu_sibling_map_mask &=

                ((1 << pcache_info[cache_type].num_cu_shared) - 1);

...
cu_sibling_map_mask = cu_sibling_map_mask >> (first_active_cu - 1);
...
It again re-uses cu_info->cu_bitmap[start][0][0]; in the second iteration. I am not sure if it is doing the right thing either. I will try to take a look at it and understand what exactly we want to achieve with this function.

Regards,
Mukul

Quoted 125 lines
Quoted 2 lines

+ cu_sibling_map_mask &= ((1 <<

pcache_info[cache_type].num_cu_shared) - 1);

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -0
+                           }
                    }
            }
            pcache->sibling_map_size = k;
@@ -1665,7 +1670,7 @@ static int fill_in_l2_l3_pcache(struct

kfd_cache_properties **props_ext,

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static int fill_in_l2_l3_pcache(struct · line 1670

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -0
  static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev,

struct kfd_node *kdev)

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -1
  {
    struct kfd_gpu_cache_info *pcache_info = NULL;
-   int i, j, k;
+   int i, j, k, xcc, start, end;
    int ct = 0;
    unsigned int cu_processor_id;
    int ret;
@@ -1699,37 +1704,42 @@ static void kfd_fill_cache_non_crat_info(struct

kfd_topology_device *dev, struct

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -0
     *                      then it will consider only one CU from
     *                      the shared unit
     */
+   start = ffs(kdev->xcc_mask) - 1;
+   end = start + NUM_XCC(kdev->xcc_mask);
+

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct

Quoted 10 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -5
    for (ct = 0; ct < num_of_cache_types; ct++) {
            cu_processor_id = gpu_processor_id;
            if (pcache_info[ct].cache_level == 1) {
-                   for (i = 0; i < pcu_info->num_shader_engines; i++) {
-                           for (j = 0; j < pcu_info-
 num_shader_arrays_per_engine; j++) {
-                                   for (k = 0; k < pcu_info-
 num_cu_per_sh; k += pcache_info[ct].num_cu_shared) {
-
-                                           ret =

fill_in_l1_pcache(&props_ext, pcache_info, pcu_info,

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct · line 1712

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -1
-
      pcu_info->cu_bitmap[0][i % 4][j + i / 4], ct,

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct · line 1713

Quoted 1 line
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -1
-
      cu_processor_id, k);

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct · line 1720

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -7
-
-                                           if (ret < 0)
-                                                   break;
-
-                                           if (!ret) {
-                                                   num_of_entries++;
-
      list_add_tail(&props_ext->list, &dev->cache_props);

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct · line 1716

Quoted 2 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2 -0
+                   for (xcc = start; xcc < end; xcc++) {
+                           for (i = 0; i < pcu_info->num_shader_engines;

i++) {

drivers/gpu/drm/amd/amdkfd/kfd_topology.c

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +2 -0
+                                   for (j = 0; j < pcu_info-
 num_shader_arrays_per_engine; j++) {
+                                           for (k = 0; k < pcu_info-

num_cu_per_sh; k +=

drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -0
+pcache_info[ct].num_cu_shared) {
+
+                                                   ret =

fill_in_l1_pcache(&props_ext, pcache_info, pcu_info,

Quoted 1 line

+

      pcu_info->cu_bitmap[xcc][i % 4][j + i / 4], ct,
Quoted 1 line

+

      cu_processor_id, k);

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct · line 1729

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +6 -0
+
+                                                   if (ret < 0)
+                                                           break;
+
+                                                   if (!ret) {
+
      num_of_entries++;
Quoted 1 line

+

      list_add_tail(&props_ext->list, &dev->cache_props);

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -0
+                                                   }
+
+                                                   /* Move to next CU

block */

Quoted 1 line

+ num_cu_shared = ((k

+ pcache_info[ct].num_cu_shared) <=

Quoted 3 lines

+ pcu_info-
num_cu_per_sh) ?
+

pcache_info[ct].num_cu_shared :

Quoted 3 lines

+ (pcu_info-
num_cu_per_sh - k);
+ cu_processor_id +=

num_cu_shared;

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_fill_cache_non_crat_info(struct kfd_topology_device *dev, struct

Quoted 4 lines
                                            }
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +0 -3
-
-                                           /* Move to next CU block */
-                                           num_cu_shared = ((k +

pcache_info[ct].num_cu_shared) <=

Quoted 3 lines

- pcu_info-
num_cu_per_sh) ?
-

pcache_info[ct].num_cu_shared :

Quoted 3 lines

- (pcu_info-
num_cu_per_sh - k);
- cu_processor_id +=

num_cu_shared;

Quoted 6 lines
                                    }
                            }
                    }
            } else {
                    ret = fill_in_l2_l3_pcache(&props_ext, pcache_info,

- pcu_info, ct,

cu_processor_id);

Quoted 18 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -0
+                                   pcu_info, ct, cu_processor_id, kdev);
 
                    if (ret < 0)
                            break;
drivers/gpu/drm/amd/amdkfd/kfd_topology.h +1 -1
index dea32a9e5506..27386ce9a021 100644
@@ -89,7 +89,7 @@ struct kfd_mem_properties {
    struct attribute        attr;
  };
 
-#define CACHE_SIBLINGMAP_SIZE 64
+#define CACHE_SIBLINGMAP_SIZE 128
 
  struct kfd_cache_properties {
    struct list_head        list;
#4 lore raw

PATCH v2 3/4 drm/amdkfd: Update CU masking for GFX 9.4.3

In reply to Mukul Joshi

The CU mask passed from user-space will change based on different spatial partitioning mode. As a result, update CU masking code for GFX9.4.3 to work for all partitioning modes.

---
v1->v2:
- Incorporate Felix's review comments.

 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c  | 28 ++++++++---
 drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h  |  2 +-
 .../gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c  |  2 +-
 .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c  |  2 +-
 .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c  |  2 +-
 .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c   | 46 ++++++++++++-------
 .../gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c   |  2 +-
 7 files changed, 56 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c +22 -6
index 763966236658..447829c22295 100644
@@ -97,14 +97,16 @@ void free_mqd_hiq_sdma(struct mqd_manager *mm, void *mqd,
 
 void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
 		const uint32_t *cu_mask, uint32_t cu_mask_count,
-		uint32_t *se_mask)
+		uint32_t *se_mask, uint32_t inst)
 {
 	struct kfd_cu_info cu_info;
 	uint32_t cu_per_sh[KFD_MAX_NUM_SE][KFD_MAX_NUM_SH_PER_SE] = {0};
 	bool wgp_mode_req = KFD_GC_VERSION(mm->dev) >= IP_VERSION(10, 0, 0);
 	uint32_t en_mask = wgp_mode_req ? 0x3 : 0x1;
-	int i, se, sh, cu, cu_bitmap_sh_mul, inc = wgp_mode_req ? 2 : 1;
+	int i, se, sh, cu, cu_bitmap_sh_mul, cu_inc = wgp_mode_req ? 2 : 1;
 	uint32_t cu_active_per_node;
+	int inc = cu_inc * NUM_XCC(mm->dev->xcc_mask);
+	int xcc_inst = inst + ffs(mm->dev->xcc_mask) - 1;
 
 	amdgpu_amdkfd_get_cu_info(mm->dev->adev, &cu_info);
 
@@ -143,7 +145,8 @@ void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
 	for (se = 0; se < cu_info.num_shader_engines; se++)
 		for (sh = 0; sh < cu_info.num_shader_arrays_per_engine; sh++)
 			cu_per_sh[se][sh] = hweight32(
-				cu_info.cu_bitmap[0][se % 4][sh + (se / 4) * cu_bitmap_sh_mul]);
+				cu_info.cu_bitmap[xcc_inst][se % 4][sh + (se / 4) *
+				cu_bitmap_sh_mul]);
 
 	/* Symmetrically map cu_mask to all SEs & SHs:
 	 * se_mask programs up to 2 SH in the upper and lower 16 bits.
@@ -166,20 +169,33 @@ void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
 	 * cu_mask[0] bit8 -> se_mask[0] bit1 (SE0,SH0,CU1)
 	 * ...
 	 *
+	 * For GFX 9.4.3, the following code only looks at a
+	 * subset of the cu_mask corresponding to the inst parameter.
+	 * If we have n XCCs under one GPU node
+	 * cu_mask[0] bit0 -> XCC0 se_mask[0] bit0 (XCC0,SE0,SH0,CU0)
+	 * cu_mask[0] bit1 -> XCC1 se_mask[0] bit0 (XCC1,SE0,SH0,CU0)
+	 * ..
+	 * cu_mask[0] bitn -> XCCn se_mask[0] bit0 (XCCn,SE0,SH0,CU0)
+	 * cu_mask[0] bit n+1 -> XCC0 se_mask[1] bit0 (XCC0,SE1,SH0,CU0)
+	 *
+	 * For example, if there are 6 XCCs under 1 KFD node, this code
+	 * running for each inst, will look at the bits as:
+	 * inst, inst + 6, inst + 12...
+	 *
 	 * First ensure all CUs are disabled, then enable user specified CUs.
 	 */
 	for (i = 0; i < cu_info.num_shader_engines; i++)
 		se_mask[i] = 0;
 
-	i = 0;
-	for (cu = 0; cu < 16; cu += inc) {
+	i = inst;
+	for (cu = 0; cu < 16; cu += cu_inc) {
 		for (sh = 0; sh < cu_info.num_shader_arrays_per_engine; sh++) {
 			for (se = 0; se < cu_info.num_shader_engines; se++) {
 				if (cu_per_sh[se][sh] > cu) {
 					if (cu_mask[i / 32] & (en_mask << (i % 32)))
 						se_mask[se] |= en_mask << (cu + sh * 16);
 					i += inc;
-					if (i == cu_mask_count)
+					if (i >= cu_mask_count)
 						return;
 				}
 			}
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h +1 -1
index 23158db7da03..57bf5e513f4d 100644
@@ -138,7 +138,7 @@ void free_mqd_hiq_sdma(struct mqd_manager *mm, void *mqd,
 
 void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
 		const uint32_t *cu_mask, uint32_t cu_mask_count,
-		uint32_t *se_mask);
+		uint32_t *se_mask, uint32_t inst);
 
 int kfd_hiq_load_mqd_kiq(struct mqd_manager *mm, void *mqd,
 		uint32_t pipe_id, uint32_t queue_id,
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c +1 -1
index ee1d32d957f2..1a4a69943c71 100644
@@ -52,7 +52,7 @@ static void update_cu_mask(struct mqd_manager *mm, void *mqd,
 		return;
 
 	mqd_symmetrically_map_cu_mask(mm,
-		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask);
+		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask, 0);
 
 	m = get_mqd(mqd);
 	m->compute_static_thread_mgmt_se0 = se_mask[0];
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +1 -1
index 83699392c808..8b7fed913526 100644
@@ -52,7 +52,7 @@ static void update_cu_mask(struct mqd_manager *mm, void *mqd,
 		return;
 
 	mqd_symmetrically_map_cu_mask(mm,
-		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask);
+		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask, 0);
 
 	m = get_mqd(mqd);
 	m->compute_static_thread_mgmt_se0 = se_mask[0];
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +1 -1
index 0bbf0edbabd4..964b5d50a77e 100644
@@ -71,7 +71,7 @@ static void update_cu_mask(struct mqd_manager *mm, void *mqd,
 	}
 
 	mqd_symmetrically_map_cu_mask(mm,
-		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask);
+		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask, 0);
 
 	m->compute_static_thread_mgmt_se0 = se_mask[0];
 	m->compute_static_thread_mgmt_se1 = se_mask[1];
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +29 -17

76 lines not on this page · raw message

drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c +1 -1
index 657c37822980..3e1a574d4ea6 100644
@@ -55,7 +55,7 @@ static void update_cu_mask(struct mqd_manager *mm, void *mqd,
 		return;
 
 	mqd_symmetrically_map_cu_mask(mm,
-		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask);
+		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask, 0);
 
 	m = get_mqd(mqd);
 	m->compute_static_thread_mgmt_se0 = se_mask[0];
Signature · 1 line
2.35.1
maintainer Reviewed-by on v2 3/4
#5 lore raw

Re: [PATCHv2 3/4] drm/amdkfd: Update CU masking for GFX 9.4.3

Quoted 6 lines · Mukul Joshi

The CU mask passed from user-space will change based on different spatial partitioning mode. As a result, update CU masking code for GFX9.4.3 to work for all partitioning modes.

Quoted 232 lines

---
v1->v2:
- Incorporate Felix's review comments.

  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c  | 28 ++++++++---
  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h  |  2 +-
  .../gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c  |  2 +-
  .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c  |  2 +-
  .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c  |  2 +-
  .../gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c   | 46 ++++++++++++-------
  .../gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c   |  2 +-
  7 files changed, 56 insertions(+), 28 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c +22 -6
index 763966236658..447829c22295 100644
@@ -97,14 +97,16 @@ void free_mqd_hiq_sdma(struct mqd_manager *mm, void *mqd,
 
  void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
  		const uint32_t *cu_mask, uint32_t cu_mask_count,
-		uint32_t *se_mask)
+		uint32_t *se_mask, uint32_t inst)
  {
  	struct kfd_cu_info cu_info;
  	uint32_t cu_per_sh[KFD_MAX_NUM_SE][KFD_MAX_NUM_SH_PER_SE] = {0};
  	bool wgp_mode_req = KFD_GC_VERSION(mm->dev) >= IP_VERSION(10, 0, 0);
  	uint32_t en_mask = wgp_mode_req ? 0x3 : 0x1;
-	int i, se, sh, cu, cu_bitmap_sh_mul, inc = wgp_mode_req ? 2 : 1;
+	int i, se, sh, cu, cu_bitmap_sh_mul, cu_inc = wgp_mode_req ? 2 : 1;
  	uint32_t cu_active_per_node;
+	int inc = cu_inc * NUM_XCC(mm->dev->xcc_mask);
+	int xcc_inst = inst + ffs(mm->dev->xcc_mask) - 1;
 
  	amdgpu_amdkfd_get_cu_info(mm->dev->adev, &cu_info);
 
@@ -143,7 +145,8 @@ void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
  	for (se = 0; se < cu_info.num_shader_engines; se++)
  		for (sh = 0; sh < cu_info.num_shader_arrays_per_engine; sh++)
  			cu_per_sh[se][sh] = hweight32(
-				cu_info.cu_bitmap[0][se % 4][sh + (se / 4) * cu_bitmap_sh_mul]);
+				cu_info.cu_bitmap[xcc_inst][se % 4][sh + (se / 4) *
+				cu_bitmap_sh_mul]);
 
  	/* Symmetrically map cu_mask to all SEs & SHs:
  	 * se_mask programs up to 2 SH in the upper and lower 16 bits.
@@ -166,20 +169,33 @@ void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
  	 * cu_mask[0] bit8 -> se_mask[0] bit1 (SE0,SH0,CU1)
  	 * ...
  	 *
+	 * For GFX 9.4.3, the following code only looks at a
+	 * subset of the cu_mask corresponding to the inst parameter.
+	 * If we have n XCCs under one GPU node
+	 * cu_mask[0] bit0 -> XCC0 se_mask[0] bit0 (XCC0,SE0,SH0,CU0)
+	 * cu_mask[0] bit1 -> XCC1 se_mask[0] bit0 (XCC1,SE0,SH0,CU0)
+	 * ..
+	 * cu_mask[0] bitn -> XCCn se_mask[0] bit0 (XCCn,SE0,SH0,CU0)
+	 * cu_mask[0] bit n+1 -> XCC0 se_mask[1] bit0 (XCC0,SE1,SH0,CU0)
+	 *
+	 * For example, if there are 6 XCCs under 1 KFD node, this code
+	 * running for each inst, will look at the bits as:
+	 * inst, inst + 6, inst + 12...
+	 *
  	 * First ensure all CUs are disabled, then enable user specified CUs.
  	 */
  	for (i = 0; i < cu_info.num_shader_engines; i++)
  		se_mask[i] = 0;
 
-	i = 0;
-	for (cu = 0; cu < 16; cu += inc) {
+	i = inst;
+	for (cu = 0; cu < 16; cu += cu_inc) {
  		for (sh = 0; sh < cu_info.num_shader_arrays_per_engine; sh++) {
  			for (se = 0; se < cu_info.num_shader_engines; se++) {
  				if (cu_per_sh[se][sh] > cu) {
  					if (cu_mask[i / 32] & (en_mask << (i % 32)))
  						se_mask[se] |= en_mask << (cu + sh * 16);
  					i += inc;
-					if (i == cu_mask_count)
+					if (i >= cu_mask_count)
  						return;
  				}
  			}
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.h +1 -1
index 23158db7da03..57bf5e513f4d 100644
@@ -138,7 +138,7 @@ void free_mqd_hiq_sdma(struct mqd_manager *mm, void *mqd,
 
  void mqd_symmetrically_map_cu_mask(struct mqd_manager *mm,
  		const uint32_t *cu_mask, uint32_t cu_mask_count,
-		uint32_t *se_mask);
+		uint32_t *se_mask, uint32_t inst);
 
  int kfd_hiq_load_mqd_kiq(struct mqd_manager *mm, void *mqd,
  		uint32_t pipe_id, uint32_t queue_id,
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_cik.c +1 -1
index ee1d32d957f2..1a4a69943c71 100644
@@ -52,7 +52,7 @@ static void update_cu_mask(struct mqd_manager *mm, void *mqd,
  		return;
 
  	mqd_symmetrically_map_cu_mask(mm,
-		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask);
+		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask, 0);
 
  	m = get_mqd(mqd);
  	m->compute_static_thread_mgmt_se0 = se_mask[0];
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v10.c +1 -1
index 83699392c808..8b7fed913526 100644
@@ -52,7 +52,7 @@ static void update_cu_mask(struct mqd_manager *mm, void *mqd,
  		return;
 
  	mqd_symmetrically_map_cu_mask(mm,
-		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask);
+		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask, 0);
 
  	m = get_mqd(mqd);
  	m->compute_static_thread_mgmt_se0 = se_mask[0];
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v11.c +1 -1
index 0bbf0edbabd4..964b5d50a77e 100644
@@ -71,7 +71,7 @@ static void update_cu_mask(struct mqd_manager *mm, void *mqd,
  	}
 
  	mqd_symmetrically_map_cu_mask(mm,
-		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask);
+		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask, 0);
 
  	m->compute_static_thread_mgmt_se0 = se_mask[0];
  	m->compute_static_thread_mgmt_se1 = se_mask[1];
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_v9.c +29 -17
index e23d32f35607..42d881809dc7 100644
@@ -60,7 +60,7 @@ static inline struct v9_sdma_mqd *get_sdma_mqd(void *mqd)
  }
 
  static void update_cu_mask(struct mqd_manager *mm, void *mqd,
-			struct mqd_update_info *minfo)
+			struct mqd_update_info *minfo, uint32_t inst)
  {
  	struct v9_mqd *m;
  	uint32_t se_mask[KFD_MAX_NUM_SE] = {0};
@@ -69,27 +69,36 @@ static void update_cu_mask(struct mqd_manager *mm, void *mqd,
  		return;
 
  	mqd_symmetrically_map_cu_mask(mm,
-		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask);
+		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask, inst);
 
  	m = get_mqd(mqd);
+
  	m->compute_static_thread_mgmt_se0 = se_mask[0];
  	m->compute_static_thread_mgmt_se1 = se_mask[1];
  	m->compute_static_thread_mgmt_se2 = se_mask[2];
  	m->compute_static_thread_mgmt_se3 = se_mask[3];
-	m->compute_static_thread_mgmt_se4 = se_mask[4];
-	m->compute_static_thread_mgmt_se5 = se_mask[5];
-	m->compute_static_thread_mgmt_se6 = se_mask[6];
-	m->compute_static_thread_mgmt_se7 = se_mask[7];
-
-	pr_debug("update cu mask to %#x %#x %#x %#x %#x %#x %#x %#x\n",
-		m->compute_static_thread_mgmt_se0,
-		m->compute_static_thread_mgmt_se1,
-		m->compute_static_thread_mgmt_se2,
-		m->compute_static_thread_mgmt_se3,
-		m->compute_static_thread_mgmt_se4,
-		m->compute_static_thread_mgmt_se5,
-		m->compute_static_thread_mgmt_se6,
-		m->compute_static_thread_mgmt_se7);
+	if (KFD_GC_VERSION(mm->dev) != IP_VERSION(9, 4, 3)) {
+		m->compute_static_thread_mgmt_se4 = se_mask[4];
+		m->compute_static_thread_mgmt_se5 = se_mask[5];
+		m->compute_static_thread_mgmt_se6 = se_mask[6];
+		m->compute_static_thread_mgmt_se7 = se_mask[7];
+
+		pr_debug("update cu mask to %#x %#x %#x %#x %#x %#x %#x %#x\n",
+			m->compute_static_thread_mgmt_se0,
+			m->compute_static_thread_mgmt_se1,
+			m->compute_static_thread_mgmt_se2,
+			m->compute_static_thread_mgmt_se3,
+			m->compute_static_thread_mgmt_se4,
+			m->compute_static_thread_mgmt_se5,
+			m->compute_static_thread_mgmt_se6,
+			m->compute_static_thread_mgmt_se7);
+	} else {
+		pr_debug("inst: %u, update cu mask to %#x %#x %#x %#x\n",
+			inst, m->compute_static_thread_mgmt_se0,
+			m->compute_static_thread_mgmt_se1,
+			m->compute_static_thread_mgmt_se2,
+			m->compute_static_thread_mgmt_se3);
+	}
  }
 
  static void set_priority(struct v9_mqd *m, struct queue_properties *q)
@@ -290,7 +299,8 @@ static void update_mqd(struct mqd_manager *mm, void *mqd,
  	if (mm->dev->kfd->cwsr_enabled && q->ctx_save_restore_area_address)
  		m->cp_hqd_ctx_save_control = 0;
 
-	update_cu_mask(mm, mqd, minfo);
+	if (KFD_GC_VERSION(mm->dev) != IP_VERSION(9, 4, 3))
+		update_cu_mask(mm, mqd, minfo, 0);
  	set_priority(m, q);
 
  	q->is_active = QUEUE_IS_ACTIVE(*q);
@@ -676,6 +686,8 @@ static void update_mqd_v9_4_3(struct mqd_manager *mm, void *mqd,
  		m = get_mqd(mqd + size * xcc);
  		update_mqd(mm, m, q, minfo);
 
+		update_cu_mask(mm, mqd, minfo, xcc);
+
  		if (q->format == KFD_QUEUE_FORMAT_AQL) {
  			switch (xcc) {
  			case 0:
drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager_vi.c +1 -1
index 657c37822980..3e1a574d4ea6 100644
@@ -55,7 +55,7 @@ static void update_cu_mask(struct mqd_manager *mm, void *mqd,
  		return;
 
  	mqd_symmetrically_map_cu_mask(mm,
-		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask);
+		minfo->cu_mask.ptr, minfo->cu_mask.count, se_mask, 0);
 
  	m = get_mqd(mqd);
  	m->compute_static_thread_mgmt_se0 = se_mask[0];
#6 lore raw

PATCH 4/4 drm/amdgpu: Rename KGD_MAX_QUEUES to AMDGPU_MAX_QUEUES

In reply to Mukul Joshi

Rename KGD_MAX_QUEUES to AMDGPU_MAX_QUEUES to conform with the naming convention followed in amdgpu_gfx.h. No functional change.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c            | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c     | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h               | 6 +++---
 drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 4 ++--
 drivers/gpu/drm/amd/include/kgd_kfd_interface.h       | 2 +-
 5 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +2 -2
index 25d5fda5b243..26ff5f8d9795 100644
@@ -164,7 +164,7 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
 		 */
 		bitmap_complement(gpu_resources.cp_queue_bitmap,
 				  adev->gfx.mec_bitmap[0].queue_bitmap,
-				  KGD_MAX_QUEUES);
+				  AMDGPU_MAX_QUEUES);
 
 		/* According to linux/bitmap.h we shouldn't use bitmap_clear if
 		 * nbits is not compile time constant
@@ -172,7 +172,7 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
 		last_valid_bit = 1 /* only first MEC can have compute queues */
 				* adev->gfx.mec.num_pipe_per_mec
 				* adev->gfx.mec.num_queue_per_pipe;
-		for (i = last_valid_bit; i < KGD_MAX_QUEUES; ++i)
+		for (i = last_valid_bit; i < AMDGPU_MAX_QUEUES; ++i)
 			clear_bit(i, gpu_resources.cp_queue_bitmap);
 
 		amdgpu_doorbell_get_kfd_info(adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +2 -2
index 3c45a188b701..04b8c7dacd30 100644
@@ -1037,7 +1037,7 @@ void kgd_gfx_v9_get_cu_occupancy(struct amdgpu_device *adev, int pasid,
 	int pasid_tmp;
 	int max_queue_cnt;
 	int vmid_wave_cnt = 0;
-	DECLARE_BITMAP(cp_queue_bitmap, KGD_MAX_QUEUES);
+	DECLARE_BITMAP(cp_queue_bitmap, AMDGPU_MAX_QUEUES);
 
 	lock_spi_csq_mutexes(adev);
 	soc15_grbm_select(adev, 1, 0, 0, 0, inst);
@@ -1047,7 +1047,7 @@ void kgd_gfx_v9_get_cu_occupancy(struct amdgpu_device *adev, int pasid,
 	 * to get number of waves in flight
 	 */
 	bitmap_complement(cp_queue_bitmap, adev->gfx.mec_bitmap[0].queue_bitmap,
-			  KGD_MAX_QUEUES);
+			  AMDGPU_MAX_QUEUES);
 	max_queue_cnt = adev->gfx.mec.num_pipe_per_mec *
 			adev->gfx.mec.num_queue_per_pipe;
 	sh_cnt = adev->gfx.config.max_sh_per_se;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -3
index 0ca95c4d4bfb..42ac6d1bf9ca 100644
@@ -43,10 +43,10 @@
 #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
 
 #define AMDGPU_MAX_GC_INSTANCES		8
-#define KGD_MAX_QUEUES			128
+#define AMDGPU_MAX_QUEUES		128
 
-#define AMDGPU_MAX_GFX_QUEUES KGD_MAX_QUEUES
-#define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
+#define AMDGPU_MAX_GFX_QUEUES AMDGPU_MAX_QUEUES
+#define AMDGPU_MAX_COMPUTE_QUEUES AMDGPU_MAX_QUEUES
 
 enum amdgpu_gfx_pipe_priority {
 	AMDGPU_GFX_PIPE_PRIO_NORMAL = AMDGPU_RING_PRIO_1,
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2 -2
index 4170e3d32630..6d07a5dd2648 100644
@@ -92,7 +92,7 @@ static bool is_pipe_enabled(struct device_queue_manager *dqm, int mec, int pipe)
 unsigned int get_cp_queues_num(struct device_queue_manager *dqm)
 {
 	return bitmap_weight(dqm->dev->kfd->shared_resources.cp_queue_bitmap,
-				KGD_MAX_QUEUES);
+				AMDGPU_MAX_QUEUES);
 }
 
 unsigned int get_queues_per_pipe(struct device_queue_manager *dqm)
@@ -1576,7 +1576,7 @@ static int set_sched_resources(struct device_queue_manager *dqm)
 	res.vmid_mask = dqm->dev->compute_vmid_bitmap;
 
 	res.queue_mask = 0;
-	for (i = 0; i < KGD_MAX_QUEUES; ++i) {
+	for (i = 0; i < AMDGPU_MAX_QUEUES; ++i) {
 		mec = (i / dqm->dev->kfd->shared_resources.num_queue_per_pipe)
 			/ dqm->dev->kfd->shared_resources.num_pipe_per_mec;
 
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1 -1
index 3b5a56585c4b..255adc30f802 100644
@@ -123,7 +123,7 @@ struct kgd2kfd_shared_resources {
 	uint32_t num_queue_per_pipe;
 
 	/* Bit n == 1 means Queue n is available for KFD */
-	DECLARE_BITMAP(cp_queue_bitmap, KGD_MAX_QUEUES);
+	DECLARE_BITMAP(cp_queue_bitmap, AMDGPU_MAX_QUEUES);
 
 	/* SDMA doorbell assignments (SOC15 and later chips only). Only
 	 * specific doorbells are routed to each SDMA engine. Others
Signature · 1 line
2.35.1
maintainer Reviewed-by on v1 4/4
#7 lore raw

Re: [PATCH 4/4] drm/amdgpu: Rename KGD_MAX_QUEUES to AMDGPU_MAX_QUEUES

Quoted 5 lines · Mukul Joshi

Rename KGD_MAX_QUEUES to AMDGPU_MAX_QUEUES to conform with the naming convention followed in amdgpu_gfx.h. No functional change.

Quoted 105 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c            | 4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c     | 4 ++--
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h               | 6 +++---
  drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c | 4 ++--
  drivers/gpu/drm/amd/include/kgd_kfd_interface.h       | 2 +-
  5 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +2 -2
index 25d5fda5b243..26ff5f8d9795 100644
@@ -164,7 +164,7 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
  		 */
  		bitmap_complement(gpu_resources.cp_queue_bitmap,
  				  adev->gfx.mec_bitmap[0].queue_bitmap,
-				  KGD_MAX_QUEUES);
+				  AMDGPU_MAX_QUEUES);
 
  		/* According to linux/bitmap.h we shouldn't use bitmap_clear if
  		 * nbits is not compile time constant
@@ -172,7 +172,7 @@ void amdgpu_amdkfd_device_init(struct amdgpu_device *adev)
  		last_valid_bit = 1 /* only first MEC can have compute queues */
  				* adev->gfx.mec.num_pipe_per_mec
  				* adev->gfx.mec.num_queue_per_pipe;
-		for (i = last_valid_bit; i < KGD_MAX_QUEUES; ++i)
+		for (i = last_valid_bit; i < AMDGPU_MAX_QUEUES; ++i)
  			clear_bit(i, gpu_resources.cp_queue_bitmap);
 
  		amdgpu_doorbell_get_kfd_info(adev,
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gfx_v9.c +2 -2
index 3c45a188b701..04b8c7dacd30 100644
@@ -1037,7 +1037,7 @@ void kgd_gfx_v9_get_cu_occupancy(struct amdgpu_device *adev, int pasid,
  	int pasid_tmp;
  	int max_queue_cnt;
  	int vmid_wave_cnt = 0;
-	DECLARE_BITMAP(cp_queue_bitmap, KGD_MAX_QUEUES);
+	DECLARE_BITMAP(cp_queue_bitmap, AMDGPU_MAX_QUEUES);
 
  	lock_spi_csq_mutexes(adev);
  	soc15_grbm_select(adev, 1, 0, 0, 0, inst);
@@ -1047,7 +1047,7 @@ void kgd_gfx_v9_get_cu_occupancy(struct amdgpu_device *adev, int pasid,
  	 * to get number of waves in flight
  	 */
  	bitmap_complement(cp_queue_bitmap, adev->gfx.mec_bitmap[0].queue_bitmap,
-			  KGD_MAX_QUEUES);
+			  AMDGPU_MAX_QUEUES);
  	max_queue_cnt = adev->gfx.mec.num_pipe_per_mec *
  			adev->gfx.mec.num_queue_per_pipe;
  	sh_cnt = adev->gfx.config.max_sh_per_se;
drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h +3 -3
index 0ca95c4d4bfb..42ac6d1bf9ca 100644
@@ -43,10 +43,10 @@
  #define AMDGPU_GFX_LBPW_DISABLED_MODE		0x00000008L
 
  #define AMDGPU_MAX_GC_INSTANCES		8
-#define KGD_MAX_QUEUES			128
+#define AMDGPU_MAX_QUEUES		128
 
-#define AMDGPU_MAX_GFX_QUEUES KGD_MAX_QUEUES
-#define AMDGPU_MAX_COMPUTE_QUEUES KGD_MAX_QUEUES
+#define AMDGPU_MAX_GFX_QUEUES AMDGPU_MAX_QUEUES
+#define AMDGPU_MAX_COMPUTE_QUEUES AMDGPU_MAX_QUEUES
 
  enum amdgpu_gfx_pipe_priority {
  	AMDGPU_GFX_PIPE_PRIO_NORMAL = AMDGPU_RING_PRIO_1,
drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c +2 -2
index 4170e3d32630..6d07a5dd2648 100644
@@ -92,7 +92,7 @@ static bool is_pipe_enabled(struct device_queue_manager *dqm, int mec, int pipe)
  unsigned int get_cp_queues_num(struct device_queue_manager *dqm)
  {
  	return bitmap_weight(dqm->dev->kfd->shared_resources.cp_queue_bitmap,
-				KGD_MAX_QUEUES);
+				AMDGPU_MAX_QUEUES);
  }
 
  unsigned int get_queues_per_pipe(struct device_queue_manager *dqm)
@@ -1576,7 +1576,7 @@ static int set_sched_resources(struct device_queue_manager *dqm)
  	res.vmid_mask = dqm->dev->compute_vmid_bitmap;
 
  	res.queue_mask = 0;
-	for (i = 0; i < KGD_MAX_QUEUES; ++i) {
+	for (i = 0; i < AMDGPU_MAX_QUEUES; ++i) {
  		mec = (i / dqm->dev->kfd->shared_resources.num_queue_per_pipe)
  			/ dqm->dev->kfd->shared_resources.num_pipe_per_mec;
 
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1 -1
index 3b5a56585c4b..255adc30f802 100644
@@ -123,7 +123,7 @@ struct kgd2kfd_shared_resources {
  	uint32_t num_queue_per_pipe;
 
  	/* Bit n == 1 means Queue n is available for KFD */
-	DECLARE_BITMAP(cp_queue_bitmap, KGD_MAX_QUEUES);
+	DECLARE_BITMAP(cp_queue_bitmap, AMDGPU_MAX_QUEUES);
 
  	/* SDMA doorbell assignments (SOC15 and later chips only). Only
  	 * specific doorbells are routed to each SDMA engine. Others
maintainer Reviewed-by on v2 1/4
#8 lore raw
In reply to Mukul Joshi
Quoted 6 lines · Mukul Joshi

Currently, we store CU info only for a single XCC assuming that it is the same for all XCCs. However, that may not be true. As a result, store CU info for all XCCs. This info is later used for CU masking.

One last nit-pick inline. With that fixed (or explained), the patch is

Quoted 19 lines

---
v1->v2:
- Incorporate Felix's review comments.

  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |  3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  4 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c       | 76 +++++++++----------
  drivers/gpu/drm/amd/amdkfd/kfd_crat.c         |  3 +-
  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c  |  8 +-
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c     | 11 ++-
  .../gpu/drm/amd/include/kgd_kfd_interface.h   |  6 +-
  14 files changed, 60 insertions(+), 65 deletions(-)

[snip]

drivers/gpu/drm/amd/include/kgd_kfd_interface.h line 35

Quoted 10 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +2 -0
index f3f40dbb8ff7..3b5a56585c4b 100644
@@ -31,12 +31,12 @@
  #include <linux/types.h>
  #include <linux/bitmap.h>
  #include <linux/dma-fence.h>
+#include "amdgpu_irq.h"
+#include "amdgpu_gfx.h"

Why do we need to include amdgpu_irq.h here?

Regards,
  Felix

Quoted 18 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1 -3
  struct pci_dev;
  struct amdgpu_device;
 
-#define KGD_MAX_QUEUES 128
-
  struct kfd_dev;
  struct kgd_mem;
 
@@ -68,7 +68,7 @@ struct kfd_cu_info {
  	uint32_t wave_front_size;
  	uint32_t max_scratch_slots_per_cu;
  	uint32_t lds_size;
-	uint32_t cu_bitmap[4][4];
+	uint32_t cu_bitmap[AMDGPU_MAX_GC_INSTANCES][4][4];
  };
 
  /* For getting GPU local memory information from KGD */
#9 lore raw

[AMD Official Use Only - General]

Quoted 43 lines

-----Original Message-----
From: Kuehling, Felix <[email protected]>
Sent: Thursday, September 7, 2023 4:31 PM
To: Joshi, Mukul <[email protected]>; [email protected]
Subject: Re: [PATCHv2 1/4] drm/amdgpu: Store CU info from all XCCs for GFX v9.4.3

Quoted 5 lines · Mukul Joshi

Currently, we store CU info only for a single XCC assuming that it is the same for all XCCs. However, that may not be true. As a result, store CU info for all XCCs. This info is later used for CU masking.

One last nit-pick inline. With that fixed (or explained), the patch is

Quoted 19 lines

---
v1->v2:
- Incorporate Felix's review comments.

  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c    |  2 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.h       |  3 +-
  drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c       |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v10_0.c        |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c        |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v6_0.c         |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v7_0.c         |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v8_0.c         |  2 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v9_0.c         |  4 +-
  drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3.c       | 76 +++++++++----------
  drivers/gpu/drm/amd/amdkfd/kfd_crat.c         |  3 +-
  drivers/gpu/drm/amd/amdkfd/kfd_mqd_manager.c  |  8 +-
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c     | 11 ++-
  .../gpu/drm/amd/include/kgd_kfd_interface.h   |  6 +-
  14 files changed, 60 insertions(+), 65 deletions(-)

[snip]

Quoted 14 lines

drivers/gpu/drm/amd/include/kgd_kfd_interface.h line 35

Quoted 11 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +2 -0
index f3f40dbb8ff7..3b5a56585c4b 100644
@@ -31,12 +31,12 @@
  #include <linux/types.h>
  #include <linux/bitmap.h>
  #include <linux/dma-fence.h>
+#include "amdgpu_irq.h"
+#include "amdgpu_gfx.h"

Why do we need to include amdgpu_irq.h here?

amdgpu_gfx.h has struct amdgpu_irq_src which is defined in amdgpu_irq.h. So, compilation fails if I don't include amdgpu_irq.h

Regards,
Mukul

Quoted 22 lines

Regards,
Felix

Quoted 18 lines
drivers/gpu/drm/amd/include/kgd_kfd_interface.h +1 -3
  struct pci_dev;
  struct amdgpu_device;
 
-#define KGD_MAX_QUEUES 128
-
  struct kfd_dev;
  struct kgd_mem;
 
@@ -68,7 +68,7 @@ struct kfd_cu_info {
    uint32_t wave_front_size;
    uint32_t max_scratch_slots_per_cu;
    uint32_t lds_size;
-   uint32_t cu_bitmap[4][4];
+   uint32_t cu_bitmap[AMDGPU_MAX_GC_INSTANCES][4][4];
  };
 
  /* For getting GPU local memory information from KGD */