Skip to contentSkip to conversation

drm/amdkfd: Add UALOE and UALINK IO link types

PATCH In review Alex Sierra 2 participants 3 messages Oct 26 – Oct 29

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

PATCH 1/1 drm/amdkfd: Add UALOE and UALINK IO link types

From: Alysa Liu <[email protected]>

When ualink info is available, report the specific link type (UALOE or UALINK) instead of XGMI in topology sysfs.

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c     | 18 ++++++++++++++++--
 drivers/gpu/drm/amd/amdkfd/kfd_crat.h     |  9 +++++++++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c |  6 +++---
 include/uapi/linux/kfd_sysfs.h            |  2 ++
 4 files changed, 30 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +16 -2
index 7725956e4b08..0583624e5897 100644
@@ -1254,7 +1254,7 @@ static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
 
 			if (props->iolink_type == CRAT_IOLINK_TYPE_PCIEXPRESS)
 				props->weight = 20;
-			else if (props->iolink_type == CRAT_IOLINK_TYPE_XGMI)
+			else if (crat_iolink_is_xgmi_class(props->iolink_type))
 				props->weight = iolink->weight_xgmi;
 			else
 				props->weight = node_distance(id_from, id_to);
@@ -2229,7 +2229,21 @@ static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size,
 	sub_type_hdr->flags |= CRAT_SUBTYPE_FLAGS_ENABLED |
 			       CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
 
-	sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
+	if (kdev->adev->ualink.info) {
+		switch (kdev->adev->ualink.info->link_type) {
+		case AMDGPU_UALINK_TYPE_UALOE:
+			sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_UALOE;
+			break;
+		case AMDGPU_UALINK_TYPE_UALINK:
+			sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_UALINK;
+			break;
+		default:
+			sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
+			break;
+		}
+	} else {
+		sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
+	}
 	sub_type_hdr->proximity_domain_from = proximity_domain_from;
 	sub_type_hdr->proximity_domain_to = proximity_domain_to;
 
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +9 -0
index a8ca7ecb6d27..ce78484f94a5 100644
@@ -257,8 +257,17 @@ struct crat_subtype_ccompute {
 #define CRAT_IOLINK_TYPE_ETHERNET_RDMA	14
 #define CRAT_IOLINK_TYPE_RDMA_OTHER	15
 #define CRAT_IOLINK_TYPE_OTHER		16
+#define CRAT_IOLINK_TYPE_UALOE		17
+#define CRAT_IOLINK_TYPE_UALINK		18
 #define CRAT_IOLINK_TYPE_MAX		255
 
+static inline bool crat_iolink_is_xgmi_class(uint32_t type)
+{
+	return type == CRAT_IOLINK_TYPE_XGMI ||
+	       type == CRAT_IOLINK_TYPE_UALOE ||
+	       type == CRAT_IOLINK_TYPE_UALINK;
+}
+
 #define CRAT_IOLINK_RESERVED_LENGTH	24
 
 struct crat_subtype_iolink {
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +3 -3
index 8689f4110afc..1863a944d44d 100644
@@ -1473,7 +1473,7 @@ static void kfd_set_iolink_no_atomics(struct kfd_topology_device *dev,
 					struct kfd_iolink_properties *link)
 {
 	/* xgmi always supports atomics between links. */
-	if (link->iolink_type == CRAT_IOLINK_TYPE_XGMI)
+	if (crat_iolink_is_xgmi_class(link->iolink_type))
 		return;
 
 	/* checkout source dev has atomics support on root. */
@@ -1572,7 +1572,7 @@ static void kfd_set_recommended_sdma_engines(struct kfd_topology_device *to_dev,
 			inbound_link->rec_sdma_eng_id_mask = xgmi_sdma_eng_id_mask;
 
 	} else {
-		uint32_t engine_mask = (outbound_link->iolink_type == CRAT_IOLINK_TYPE_XGMI &&
+		uint32_t engine_mask = (crat_iolink_is_xgmi_class(outbound_link->iolink_type) &&
 				num_xgmi_sdma_engines && to_dev->gpu) ? xgmi_sdma_eng_id_mask :
 				sdma_eng_id_mask;
 
@@ -1601,7 +1601,7 @@ static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)
 
 		/* Include the CPU peer in GPU hive if connected over xGMI. */
 		if (!peer_dev->gpu &&
-		    link->iolink_type == CRAT_IOLINK_TYPE_XGMI) {
+		    crat_iolink_is_xgmi_class(link->iolink_type)) {
 			/*
 			 * If the GPU is not part of a GPU hive, use its pci
 			 * device location as the hive ID to bind with the CPU.
include/uapi/linux/kfd_sysfs.h +2 -0
index 0b6ce2f3c887..b11f9bcae7f8 100644
@@ -114,6 +114,8 @@
 #define HSA_IOLINK_TYPE_ETHERNET_RDMA	14
 #define HSA_IOLINK_TYPE_RDMA_OTHER	15
 #define HSA_IOLINK_TYPE_OTHER		16
+#define HSA_IOLINK_TYPE_UALOE		17
+#define HSA_IOLINK_TYPE_UALINK		18
 
 /* Flag bits in IO link properties (matches CRAT flags, excluding the
  * bi-directional flag, which is not offially part of the CRAT spec, and
Signature · 1 line
2.34.1
#1 lore raw
Quoted 18 lines · Alex Sierra

From: Alysa Liu <[email protected]>

When ualink info is available, report the specific link type (UALOE or UALINK) instead of XGMI in topology sysfs.

---
  drivers/gpu/drm/amd/amdkfd/kfd_crat.c     | 18 ++++++++++++++++--
  drivers/gpu/drm/amd/amdkfd/kfd_crat.h     |  9 +++++++++
  drivers/gpu/drm/amd/amdkfd/kfd_topology.c |  6 +++---
  include/uapi/linux/kfd_sysfs.h            |  2 ++
  4 files changed, 30 insertions(+), 5 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +0 -0
index 7725956e4b08..0583624e5897 100644

drivers/gpu/drm/amd/amdkfd/kfd_crat.c static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink, · line 1258

Quoted 6 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -1
@@ -1254,7 +1254,7 @@ static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
 
  			if (props->iolink_type == CRAT_IOLINK_TYPE_PCIEXPRESS)
  				props->weight = 20;
-			else if (props->iolink_type == CRAT_IOLINK_TYPE_XGMI)
+			else if (crat_iolink_is_xgmi_class(props->iolink_type))
  				props->weight = iolink->weight_xgmi;

Should there be different weight values for UALOE vs UALINK?

Quoted 61 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +15 -1
  			else
  				props->weight = node_distance(id_from, id_to);
@@ -2229,7 +2229,21 @@ static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size,
  	sub_type_hdr->flags |= CRAT_SUBTYPE_FLAGS_ENABLED |
  			       CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
 
-	sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
+	if (kdev->adev->ualink.info) {
+		switch (kdev->adev->ualink.info->link_type) {
+		case AMDGPU_UALINK_TYPE_UALOE:
+			sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_UALOE;
+			break;
+		case AMDGPU_UALINK_TYPE_UALINK:
+			sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_UALINK;
+			break;
+		default:
+			sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
+			break;
+		}
+	} else {
+		sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
+	}
  	sub_type_hdr->proximity_domain_from = proximity_domain_from;
  	sub_type_hdr->proximity_domain_to = proximity_domain_to;
 
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +9 -0
index a8ca7ecb6d27..ce78484f94a5 100644
@@ -257,8 +257,17 @@ struct crat_subtype_ccompute {
  #define CRAT_IOLINK_TYPE_ETHERNET_RDMA	14
  #define CRAT_IOLINK_TYPE_RDMA_OTHER	15
  #define CRAT_IOLINK_TYPE_OTHER		16
+#define CRAT_IOLINK_TYPE_UALOE		17
+#define CRAT_IOLINK_TYPE_UALINK		18
  #define CRAT_IOLINK_TYPE_MAX		255
 
+static inline bool crat_iolink_is_xgmi_class(uint32_t type)
+{
+	return type == CRAT_IOLINK_TYPE_XGMI ||
+	       type == CRAT_IOLINK_TYPE_UALOE ||
+	       type == CRAT_IOLINK_TYPE_UALINK;
+}
+
  #define CRAT_IOLINK_RESERVED_LENGTH	24
 
  struct crat_subtype_iolink {
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -1
index 8689f4110afc..1863a944d44d 100644
@@ -1473,7 +1473,7 @@ static void kfd_set_iolink_no_atomics(struct kfd_topology_device *dev,
  					struct kfd_iolink_properties *link)
  {
  	/* xgmi always supports atomics between links. */
-	if (link->iolink_type == CRAT_IOLINK_TYPE_XGMI)
+	if (crat_iolink_is_xgmi_class(link->iolink_type))
  		return;
 
  	/* checkout source dev has atomics support on root. */

drivers/gpu/drm/amd/amdkfd/kfd_topology.c static void kfd_set_recommended_sdma_engines(struct kfd_topology_device *to_dev, · line 1577

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -1
@@ -1572,7 +1572,7 @@ static void kfd_set_recommended_sdma_engines(struct kfd_topology_device *to_dev,
  			inbound_link->rec_sdma_eng_id_mask = xgmi_sdma_eng_id_mask;
 
  	} else {
-		uint32_t engine_mask = (outbound_link->iolink_type == CRAT_IOLINK_TYPE_XGMI &&
+		uint32_t engine_mask = (crat_iolink_is_xgmi_class(outbound_link->iolink_type) &&
  				num_xgmi_sdma_engines && to_dev->gpu) ? xgmi_sdma_eng_id_mask :
  				sdma_eng_id_mask;

This may not hold anymore for SOCs supporting ualink. Instead of dedicated sdma engines, probably everything can be shown as available.

Thanks,
Lijo

Quoted 23 lines
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +1 -1
@@ -1601,7 +1601,7 @@ static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)
 
  		/* Include the CPU peer in GPU hive if connected over xGMI. */
  		if (!peer_dev->gpu &&
-		    link->iolink_type == CRAT_IOLINK_TYPE_XGMI) {
+		    crat_iolink_is_xgmi_class(link->iolink_type)) {
  			/*
  			 * If the GPU is not part of a GPU hive, use its pci
  			 * device location as the hive ID to bind with the CPU.
include/uapi/linux/kfd_sysfs.h +2 -0
index 0b6ce2f3c887..b11f9bcae7f8 100644
@@ -114,6 +114,8 @@
  #define HSA_IOLINK_TYPE_ETHERNET_RDMA	14
  #define HSA_IOLINK_TYPE_RDMA_OTHER	15
  #define HSA_IOLINK_TYPE_OTHER		16
+#define HSA_IOLINK_TYPE_UALOE		17
+#define HSA_IOLINK_TYPE_UALINK		18
 
  /* Flag bits in IO link properties (matches CRAT flags, excluding the
   * bi-directional flag, which is not offially part of the CRAT spec, and
#2 lore raw

PATCH 1/1 drm/amdkfd: Add UALOE and UALINK IO link types

In reply to Alex Sierra

From: Alysa Liu <[email protected]>

When ualink info is available, report the specific link type (UALOE or UALINK) instead of XGMI in topology sysfs.

UALink and UALoE use different link weights so userspace can prefer native UALink over UALink-over-Ethernet. UALink links advertise every SDMA engine, since those SOCs do not reserve a dedicated xGMI SDMA set.

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c     | 60 +++++++++++++++++++++--
 drivers/gpu/drm/amd/amdkfd/kfd_crat.h     | 13 +++++
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 17 +++++--
 include/uapi/linux/kfd_sysfs.h            |  2 +
 4 files changed, 85 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +56 -4
index 2c49c3f0789f..35f9d693d2b0 100644
@@ -1252,9 +1252,14 @@ static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
 			props->ver_min = iolink->version_minor;
 			props->iolink_type = iolink->io_interface_type;
 
+			/*
+			 * weight_xgmi stores the link cost for xGMI, UALink,
+			 * and UALoE. It is selected per link type when the
+			 * IO link record is built.
+			 */
 			if (props->iolink_type == CRAT_IOLINK_TYPE_PCIEXPRESS)
 				props->weight = 20;
-			else if (props->iolink_type == CRAT_IOLINK_TYPE_XGMI)
+			else if (crat_iolink_is_xgmi_class(props->iolink_type))
 				props->weight = iolink->weight_xgmi;
 			else
 				props->weight = node_distance(id_from, id_to);
@@ -2132,6 +2137,26 @@ static void kfd_find_numa_node_in_srat(struct kfd_node *kdev)
 
 #define KFD_CRAT_INTRA_SOCKET_WEIGHT	13
 #define KFD_CRAT_XGMI_WEIGHT		15
+/*
+ * Relative link cost, lower is preferred. PCIe is 20.
+ * Native UALink is a scale-up load/store fabric in the same class as xGMI.
+ * UALoE (UALink over Ethernet) is a higher-latency path, so it costs more
+ * than UALink but stays preferred over PCIe.
+ */
+#define KFD_CRAT_UALINK_WEIGHT		15
+#define KFD_CRAT_UALOE_WEIGHT		18
+
+static uint8_t kfd_crat_iolink_base_weight(uint8_t io_type)
+{
+	switch (io_type) {
+	case CRAT_IOLINK_TYPE_UALOE:
+		return KFD_CRAT_UALOE_WEIGHT;
+	case CRAT_IOLINK_TYPE_UALINK:
+		return KFD_CRAT_UALINK_WEIGHT;
+	default:
+		return KFD_CRAT_XGMI_WEIGHT;
+	}
+}
 
 /* kfd_fill_gpu_direct_io_link - Fill in direct io link from GPU
  * to its NUMA node
@@ -2234,13 +2259,38 @@ static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size,
 	sub_type_hdr->flags |= CRAT_SUBTYPE_FLAGS_ENABLED |
 			       CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
 
-	sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
+	if (kdev->adev->ualink.info) {
+		switch (kdev->adev->ualink.info->link_type) {
+		case AMDGPU_UALINK_TYPE_UALOE:
+			sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_UALOE;
+			break;
+		case AMDGPU_UALINK_TYPE_UALINK:
+			sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_UALINK;
+			break;
+		default:
+			sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
+			break;
+		}
+	} else {
+		sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
+	}
 	sub_type_hdr->proximity_domain_from = proximity_domain_from;
 	sub_type_hdr->proximity_domain_to = proximity_domain_to;
 
 	if (use_ta_info) {
-		sub_type_hdr->weight_xgmi = KFD_CRAT_XGMI_WEIGHT *
+		unsigned int hops =
 			amdgpu_xgmi_get_hops_count(kdev->adev, peer_kdev->adev);
+		uint8_t base = kfd_crat_iolink_base_weight(sub_type_hdr->io_interface_type);
+
+		/*
+		 * Hop count comes from the xGMI topology and is zero when the
+		 * peer is not listed there. A UALink/UALoE direct link still
+		 * needs its own base weight in that case.
+		 */
+		if (!hops && crat_iolink_is_ual(sub_type_hdr->io_interface_type))
+			hops = 1;
+
+		sub_type_hdr->weight_xgmi = base * hops;
 		amdgpu_xgmi_get_bandwidth(kdev->adev, peer_kdev->adev,
 					  AMDGPU_XGMI_BW_MODE_PER_PEER,
 					  AMDGPU_XGMI_BW_UNIT_MBYTES,
@@ -2248,8 +2298,10 @@ static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size,
 					  &sub_type_hdr->maximum_bandwidth_mbs);
 	} else {
 		bool is_single_hop = kdev->kfd == peer_kdev->kfd;
+		uint8_t link_weight =
+			kfd_crat_iolink_base_weight(sub_type_hdr->io_interface_type);
 		int weight = is_single_hop ? KFD_CRAT_INTRA_SOCKET_WEIGHT :
-			(2 * KFD_CRAT_INTRA_SOCKET_WEIGHT) + KFD_CRAT_XGMI_WEIGHT;
+			(2 * KFD_CRAT_INTRA_SOCKET_WEIGHT) + link_weight;
 		int mem_bw = 819200;
 
 		sub_type_hdr->weight_xgmi = weight;
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +13 -0
index ff6ecae34a5e..f640c0398546 100644
@@ -257,8 +257,21 @@ struct crat_subtype_ccompute {
 #define CRAT_IOLINK_TYPE_ETHERNET_RDMA	14
 #define CRAT_IOLINK_TYPE_RDMA_OTHER	15
 #define CRAT_IOLINK_TYPE_OTHER		16
+#define CRAT_IOLINK_TYPE_UALOE		17
+#define CRAT_IOLINK_TYPE_UALINK		18
 #define CRAT_IOLINK_TYPE_MAX		255
 
+static inline bool crat_iolink_is_ual(uint32_t type)
+{
+	return type == CRAT_IOLINK_TYPE_UALOE ||
+	       type == CRAT_IOLINK_TYPE_UALINK;
+}
+
+static inline bool crat_iolink_is_xgmi_class(uint32_t type)
+{
+	return type == CRAT_IOLINK_TYPE_XGMI || crat_iolink_is_ual(type);
+}
+
 #define CRAT_IOLINK_RESERVED_LENGTH	24
 
 struct crat_subtype_iolink {
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +14 -3
index 5c3a134a9e5c..9fa26a01ebfb 100644
@@ -1215,7 +1215,7 @@ static void kfd_set_iolink_no_atomics(struct kfd_topology_device *dev,
 					struct kfd_iolink_properties *link)
 {
 	/* xgmi always supports atomics between links. */
-	if (link->iolink_type == CRAT_IOLINK_TYPE_XGMI)
+	if (crat_iolink_is_xgmi_class(link->iolink_type))
 		return;
 
 	/* check pcie support to set cpu(dev) flags for target_gpu_dev link. */
@@ -1283,8 +1283,13 @@ static void kfd_set_recommended_sdma_engines(struct kfd_topology_device *to_dev,
 	uint32_t sdma_eng_id_mask = (1 << num_sdma_engines) - 1;
 	uint32_t xgmi_sdma_eng_id_mask =
 			((1 << num_xgmi_sdma_engines) - 1) << num_sdma_engines;
+	bool ual_link = crat_iolink_is_ual(outbound_link->iolink_type);
 
-	bool support_rec_eng = !amdgpu_sriov_vf(adev) && to_dev->gpu &&
+	/*
+	 * The per-socket recommended-engine map is an xGMI property.
+	 * UALink SOCs do not reserve dedicated SDMA engines.
+	 */
+	bool support_rec_eng = !ual_link && !amdgpu_sriov_vf(adev) && to_dev->gpu &&
 		adev->aid_mask && num_xgmi_nodes && gpu->kfd->num_nodes == 1 &&
 		num_xgmi_sdma_engines >= 6 && (!(adev->flags & AMD_IS_APU) &&
 		num_xgmi_nodes == 8);
@@ -1305,6 +1310,12 @@ static void kfd_set_recommended_sdma_engines(struct kfd_topology_device *to_dev,
 		if (inbound_link->rec_sdma_eng_id_mask & sdma_eng_id_mask)
 			inbound_link->rec_sdma_eng_id_mask = xgmi_sdma_eng_id_mask;
 
+	} else if (ual_link) {
+		/* No dedicated fabric SDMA engines; every engine is usable. */
+		uint32_t engine_mask = sdma_eng_id_mask | xgmi_sdma_eng_id_mask;
+
+		outbound_link->rec_sdma_eng_id_mask = engine_mask;
+		inbound_link->rec_sdma_eng_id_mask = engine_mask;
 	} else {
 		uint32_t engine_mask = (outbound_link->iolink_type == CRAT_IOLINK_TYPE_XGMI &&
 				num_xgmi_sdma_engines && to_dev->gpu) ? xgmi_sdma_eng_id_mask :
@@ -1335,7 +1346,7 @@ static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)
 
 		/* Include the CPU peer in GPU hive if connected over xGMI. */
 		if (!peer_dev->gpu &&
-		    link->iolink_type == CRAT_IOLINK_TYPE_XGMI) {
+		    crat_iolink_is_xgmi_class(link->iolink_type)) {
 			/*
 			 * If the GPU is not part of a GPU hive, use its pci
 			 * device location as the hive ID to bind with the CPU.
include/uapi/linux/kfd_sysfs.h +2 -0
index 0b6ce2f3c887..b11f9bcae7f8 100644
@@ -114,6 +114,8 @@
 #define HSA_IOLINK_TYPE_ETHERNET_RDMA	14
 #define HSA_IOLINK_TYPE_RDMA_OTHER	15
 #define HSA_IOLINK_TYPE_OTHER		16
+#define HSA_IOLINK_TYPE_UALOE		17
+#define HSA_IOLINK_TYPE_UALINK		18
 
 /* Flag bits in IO link properties (matches CRAT flags, excluding the
  * bi-directional flag, which is not offially part of the CRAT spec, and
Signature · 1 line
2.34.1