Skip to contentSkip to conversation

drm/amdgpu: add psp command to get num xgmi links between direct peers

PATCH In review Jonathan Kim 3 participants 8 messages Jun 21, 2021 – Jul 10, 2021

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

PATCH 1/4 drm/amdgpu: add psp command to get num xgmi links between direct peers

The TA can now be invoked to provide the number of xgmi links connecting a direct source and destination peer.
Non-direct peers will report zero links.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 23 +++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h |  1 +
 drivers/gpu/drm/amd/amdgpu/ta_xgmi_if.h | 14 +++++++++++++-
 3 files changed, 37 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c +23 -0
index 40da29d8ec1e..2af9a7a9b7de 100644
@@ -1037,6 +1037,12 @@ int psp_xgmi_get_node_id(struct psp_context *psp, uint64_t *node_id)
 	return 0;
 }
 
+static bool psp_xgmi_peer_link_info_supported(struct psp_context *psp)
+{
+	return psp->adev->asic_type == CHIP_ALDEBARAN &&
+				psp->ta_xgmi_ucode_version >= 0x2000000b;
+}
+
 int psp_xgmi_get_topology_info(struct psp_context *psp,
 			       int number_devices,
 			       struct psp_xgmi_topology_info *topology)
@@ -1080,6 +1086,23 @@ int psp_xgmi_get_topology_info(struct psp_context *psp,
 		topology->nodes[i].sdma_engine = topology_info_output->nodes[i].sdma_engine;
 	}
 
+	/* Invoke xgmi ta again to get the link information */
+	if (psp_xgmi_peer_link_info_supported(psp)) {
+		struct ta_xgmi_cmd_get_peer_link_info_output *link_info_output;
+
+		xgmi_cmd->cmd_id = TA_COMMAND_XGMI__GET_PEER_LINKS;
+
+		ret = psp_xgmi_invoke(psp, TA_COMMAND_XGMI__GET_PEER_LINKS);
+
+		if (ret)
+			return ret;
+
+		link_info_output = &xgmi_cmd->xgmi_out_message.get_link_info;
+		for (i = 0; i < topology->num_nodes; i++)
+			topology->nodes[i].num_links =
+					link_info_output->nodes[i].num_links;
+	}
+
 	return 0;
 }
 
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +1 -0
index e5dcc6713861..13f1b869f67e 100644
@@ -116,6 +116,7 @@ struct psp_xgmi_node_info {
 	uint8_t					num_hops;
 	uint8_t					is_sharing_enabled;
 	enum ta_xgmi_assigned_sdma_engine	sdma_engine;
+	uint8_t					num_links;
 };
 
 struct psp_xgmi_topology_info {
drivers/gpu/drm/amd/amdgpu/ta_xgmi_if.h +13 -1
index ac2c27b7630c..cce7127afeaa 100644
@@ -33,7 +33,8 @@ enum ta_command_xgmi {
 	TA_COMMAND_XGMI__GET_NODE_ID			= 0x01,
 	TA_COMMAND_XGMI__GET_HIVE_ID			= 0x02,
 	TA_COMMAND_XGMI__GET_GET_TOPOLOGY_INFO		= 0x03,
-	TA_COMMAND_XGMI__SET_TOPOLOGY_INFO		= 0x04
+	TA_COMMAND_XGMI__SET_TOPOLOGY_INFO		= 0x04,
+	TA_COMMAND_XGMI__GET_PEER_LINKS			= 0x0B
 };
 
 /* XGMI related enumerations */
@@ -75,6 +76,11 @@ struct ta_xgmi_node_info {
 	enum ta_xgmi_assigned_sdma_engine	sdma_engine;
 };
 
+struct ta_xgmi_peer_link_info {
+	uint64_t				node_id;
+	uint8_t					num_links;
+};
+
 struct ta_xgmi_cmd_initialize_output {
 	uint32_t	status;
 };
@@ -97,6 +103,11 @@ struct ta_xgmi_cmd_get_topology_info_output {
 	struct ta_xgmi_node_info	nodes[TA_XGMI__MAX_CONNECTED_NODES];
 };
 
+struct ta_xgmi_cmd_get_peer_link_info_output {
+	uint32_t			num_nodes;
+	struct ta_xgmi_peer_link_info	nodes[TA_XGMI__MAX_CONNECTED_NODES];
+};
+
 struct ta_xgmi_cmd_set_topology_info_input {
 	uint32_t			num_nodes;
 	struct ta_xgmi_node_info	nodes[TA_XGMI__MAX_CONNECTED_NODES];
@@ -115,6 +126,7 @@ union ta_xgmi_cmd_output {
 	struct ta_xgmi_cmd_get_node_id_output		get_node_id;
 	struct ta_xgmi_cmd_get_hive_id_output		get_hive_id;
 	struct ta_xgmi_cmd_get_topology_info_output	get_topology_info;
+	struct ta_xgmi_cmd_get_peer_link_info_output	get_link_info;
 };
 /**********************************************************/
 
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#1 lore raw

PATCH 2/4 drm/amdkfd: report num xgmi links between direct peers to the kfd

Since Min/Max bandwidth was never used, it will repurposed to report the number of xgmi links between direct peers to the KFD topology.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 15 +++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   | 12 ++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  2 ++
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c      | 11 +++++++++--
 drivers/gpu/drm/amd/amdkfd/kfd_crat.h      |  4 ++--
 6 files changed, 41 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +15 -0
index bfab2f9fdd17..c84989eda8eb 100644
@@ -553,6 +553,21 @@ uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct kgd_dev *dst, struct kgd_dev *s
 	return  (uint8_t)ret;
 }
 
+uint8_t amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *src)
+{
+	struct amdgpu_device *peer_adev = (struct amdgpu_device *)src;
+	struct amdgpu_device *adev = (struct amdgpu_device *)dst;
+	int ret = amdgpu_xgmi_get_num_links(adev, peer_adev);
+
+	if (ret < 0) {
+		DRM_ERROR("amdgpu: failed to get xgmi num links between node %d and %d. ret = %d\n",
+			adev->gmc.xgmi.physical_node_id,
+			peer_adev->gmc.xgmi.physical_node_id, ret);
+		ret = 0;
+	}
+	return  (uint8_t)ret;
+}
+
 uint64_t amdgpu_amdkfd_get_mmio_remap_phys_addr(struct kgd_dev *kgd)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index fabc68eec36a..20e4bfce62be 100644
@@ -226,6 +226,7 @@ uint32_t amdgpu_amdkfd_get_num_gws(struct kgd_dev *kgd);
 uint32_t amdgpu_amdkfd_get_asic_rev_id(struct kgd_dev *kgd);
 int amdgpu_amdkfd_get_noretry(struct kgd_dev *kgd);
 uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct kgd_dev *dst, struct kgd_dev *src);
+uint8_t amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *src);
 
 /* Read user wptr from a specified user address space with page fault
  * disabled. The memory must be pinned and mapped to the hardware when
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +12 -0
index 8567d5d77346..258cf86b32f6 100644
@@ -486,6 +486,18 @@ int amdgpu_xgmi_get_hops_count(struct amdgpu_device *adev,
 	return	-EINVAL;
 }
 
+int amdgpu_xgmi_get_num_links(struct amdgpu_device *adev,
+		struct amdgpu_device *peer_adev)
+{
+	struct psp_xgmi_topology_info *top = &adev->psp.xgmi_context.top_info;
+	int i;
+
+	for (i = 0 ; i < top->num_nodes; ++i)
+		if (top->nodes[i].node_id == peer_adev->gmc.xgmi.node_id)
+			return top->nodes[i].num_links;
+	return	-EINVAL;
+}
+
 int amdgpu_xgmi_add_device(struct amdgpu_device *adev)
 {
 	struct psp_xgmi_topology_info *top_info;
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +2 -0
index 12969c0830d5..d2189bf7d428 100644
@@ -59,6 +59,8 @@ int amdgpu_xgmi_remove_device(struct amdgpu_device *adev);
 int amdgpu_xgmi_set_pstate(struct amdgpu_device *adev, int pstate);
 int amdgpu_xgmi_get_hops_count(struct amdgpu_device *adev,
 		struct amdgpu_device *peer_adev);
+int amdgpu_xgmi_get_num_links(struct amdgpu_device *adev,
+		struct amdgpu_device *peer_adev);
 uint64_t amdgpu_xgmi_get_relative_phy_addr(struct amdgpu_device *adev,
 					   uint64_t addr);
 static inline bool amdgpu_xgmi_same_hive(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +9 -2
index c6b02aee4993..75047b77649b 100644
@@ -1034,8 +1034,8 @@ static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
 
 			props->min_latency = iolink->minimum_latency;
 			props->max_latency = iolink->maximum_latency;
-			props->min_bandwidth = iolink->minimum_bandwidth_mbs;
-			props->max_bandwidth = iolink->maximum_bandwidth_mbs;
+			props->min_bandwidth = iolink->minimum_bandwidth;
+			props->max_bandwidth = iolink->maximum_bandwidth;
 			props->rec_transfer_size =
 					iolink->recommended_transfer_size;
 
@@ -1989,6 +1989,8 @@ static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size,
 		sub_type_hdr->flags |= CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
 		sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
 		sub_type_hdr->num_hops_xgmi = 1;
+		sub_type_hdr->minimum_bandwidth = 1;
+		sub_type_hdr->maximum_bandwidth = 1;
 	} else {
 		sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_PCIEXPRESS;
 	}
@@ -2033,6 +2035,11 @@ static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size,
 	sub_type_hdr->proximity_domain_to = proximity_domain_to;
 	sub_type_hdr->num_hops_xgmi =
 		amdgpu_amdkfd_get_xgmi_hops_count(kdev->kgd, peer_kdev->kgd);
+	sub_type_hdr->maximum_bandwidth =
+		amdgpu_amdkfd_get_xgmi_num_links(kdev->kgd, peer_kdev->kgd);
+	sub_type_hdr->minimum_bandwidth =
+		sub_type_hdr->maximum_bandwidth ? 1 : 0;
+
 	return 0;
 }
 
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +2 -2
index d54ceebd346b..d1f6de5edfb9 100644
@@ -271,8 +271,8 @@ struct crat_subtype_iolink {
 	uint16_t	version_minor;
 	uint32_t	minimum_latency;
 	uint32_t	maximum_latency;
-	uint32_t	minimum_bandwidth_mbs;
-	uint32_t	maximum_bandwidth_mbs;
+	uint32_t	minimum_bandwidth;
+	uint32_t	maximum_bandwidth;
 	uint32_t	recommended_transfer_size;
 	uint8_t		reserved2[CRAT_IOLINK_RESERVED_LENGTH - 1];
 	uint8_t		num_hops_xgmi;
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
maintainer
#2 lore raw

Re: [PATCH 2/4] drm/amdkfd: report num xgmi links between direct peers to the kfd

Quoted 112 lines · Jonathan Kim

Since Min/Max bandwidth was never used, it will repurposed to report the number of xgmi links between direct peers to the KFD topology.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 15 +++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  1 +
  drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c   | 12 ++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h   |  2 ++
  drivers/gpu/drm/amd/amdkfd/kfd_crat.c      | 11 +++++++++--
  drivers/gpu/drm/amd/amdkfd/kfd_crat.h      |  4 ++--
  6 files changed, 41 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +15 -0
index bfab2f9fdd17..c84989eda8eb 100644
@@ -553,6 +553,21 @@ uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct kgd_dev *dst, struct kgd_dev *s
  	return  (uint8_t)ret;
  }
 
+uint8_t amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *src)
+{
+	struct amdgpu_device *peer_adev = (struct amdgpu_device *)src;
+	struct amdgpu_device *adev = (struct amdgpu_device *)dst;
+	int ret = amdgpu_xgmi_get_num_links(adev, peer_adev);
+
+	if (ret < 0) {
+		DRM_ERROR("amdgpu: failed to get xgmi num links between node %d and %d. ret = %d\n",
+			adev->gmc.xgmi.physical_node_id,
+			peer_adev->gmc.xgmi.physical_node_id, ret);
+		ret = 0;
+	}
+	return  (uint8_t)ret;
+}
+
  uint64_t amdgpu_amdkfd_get_mmio_remap_phys_addr(struct kgd_dev *kgd)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
index fabc68eec36a..20e4bfce62be 100644
@@ -226,6 +226,7 @@ uint32_t amdgpu_amdkfd_get_num_gws(struct kgd_dev *kgd);
  uint32_t amdgpu_amdkfd_get_asic_rev_id(struct kgd_dev *kgd);
  int amdgpu_amdkfd_get_noretry(struct kgd_dev *kgd);
  uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct kgd_dev *dst, struct kgd_dev *src);
+uint8_t amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *src);
 
  /* Read user wptr from a specified user address space with page fault
   * disabled. The memory must be pinned and mapped to the hardware when
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +12 -0
index 8567d5d77346..258cf86b32f6 100644
@@ -486,6 +486,18 @@ int amdgpu_xgmi_get_hops_count(struct amdgpu_device *adev,
  	return	-EINVAL;
  }
 
+int amdgpu_xgmi_get_num_links(struct amdgpu_device *adev,
+		struct amdgpu_device *peer_adev)
+{
+	struct psp_xgmi_topology_info *top = &adev->psp.xgmi_context.top_info;
+	int i;
+
+	for (i = 0 ; i < top->num_nodes; ++i)
+		if (top->nodes[i].node_id == peer_adev->gmc.xgmi.node_id)
+			return top->nodes[i].num_links;
+	return	-EINVAL;
+}
+
  int amdgpu_xgmi_add_device(struct amdgpu_device *adev)
  {
  	struct psp_xgmi_topology_info *top_info;
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.h +2 -0
index 12969c0830d5..d2189bf7d428 100644
@@ -59,6 +59,8 @@ int amdgpu_xgmi_remove_device(struct amdgpu_device *adev);
  int amdgpu_xgmi_set_pstate(struct amdgpu_device *adev, int pstate);
  int amdgpu_xgmi_get_hops_count(struct amdgpu_device *adev,
  		struct amdgpu_device *peer_adev);
+int amdgpu_xgmi_get_num_links(struct amdgpu_device *adev,
+		struct amdgpu_device *peer_adev);
  uint64_t amdgpu_xgmi_get_relative_phy_addr(struct amdgpu_device *adev,
  					   uint64_t addr);
  static inline bool amdgpu_xgmi_same_hive(struct amdgpu_device *adev,
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +4 -2
index c6b02aee4993..75047b77649b 100644
@@ -1034,8 +1034,8 @@ static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
 
  			props->min_latency = iolink->minimum_latency;
  			props->max_latency = iolink->maximum_latency;
-			props->min_bandwidth = iolink->minimum_bandwidth_mbs;
-			props->max_bandwidth = iolink->maximum_bandwidth_mbs;
+			props->min_bandwidth = iolink->minimum_bandwidth;
+			props->max_bandwidth = iolink->maximum_bandwidth;
  			props->rec_transfer_size =
  					iolink->recommended_transfer_size;
 
@@ -1989,6 +1989,8 @@ static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size,
  		sub_type_hdr->flags |= CRAT_IOLINK_FLAGS_BI_DIRECTIONAL;
  		sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_XGMI;
  		sub_type_hdr->num_hops_xgmi = 1;
+		sub_type_hdr->minimum_bandwidth = 1;
+		sub_type_hdr->maximum_bandwidth = 1;
  	} else {
  		sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_PCIEXPRESS;
  	}

drivers/gpu/drm/amd/amdkfd/kfd_crat.c static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size, · line 2041

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +4 -0
@@ -2033,6 +2035,11 @@ static int kfd_fill_gpu_xgmi_link_to_gpu(int *avail_size,
  	sub_type_hdr->proximity_domain_to = proximity_domain_to;
  	sub_type_hdr->num_hops_xgmi =
  		amdgpu_amdkfd_get_xgmi_hops_count(kdev->kgd, peer_kdev->kgd);
+	sub_type_hdr->maximum_bandwidth =
+		amdgpu_amdkfd_get_xgmi_num_links(kdev->kgd, peer_kdev->kgd);
+	sub_type_hdr->minimum_bandwidth =
+		sub_type_hdr->maximum_bandwidth ? 1 : 0;

Reporting the number of XGMI links directly was not my intention. We should use it to calculate the actual bandwidth. It depends on the number of links and the clocks. You can use minimum and maximum clock to calculate the min and max bandwidth. I don't think the number of parallel links changes dynamically, so minimum bandwidth should use the same number of links.

The CRAT definition seems to use MB/s as the unit.

Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -0
+
  	return 0;
  }
 
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +0 -0
index d54ceebd346b..d1f6de5edfb9 100644

drivers/gpu/drm/amd/amdkfd/kfd_crat.h struct crat_subtype_iolink { · line 275

Quoted 7 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +2 -2
@@ -271,8 +271,8 @@ struct crat_subtype_iolink {
  	uint16_t	version_minor;
  	uint32_t	minimum_latency;
  	uint32_t	maximum_latency;
-	uint32_t	minimum_bandwidth_mbs;
-	uint32_t	maximum_bandwidth_mbs;
+	uint32_t	minimum_bandwidth;
+	uint32_t	maximum_bandwidth;

I don't think we should change the CRAT definition.

Regards,
  Felix

drivers/gpu/drm/amd/amdkfd/kfd_crat.h struct crat_subtype_iolink { · line 278

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +0 -0
  	uint32_t	recommended_transfer_size;
  	uint8_t		reserved2[CRAT_IOLINK_RESERVED_LENGTH - 1];
  	uint8_t		num_hops_xgmi;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#3 lore raw

PATCH 3/4 drm/amdkfd: report pcie bandwidth as number of lanes

In reply to Jonathan Kim

Similar to xGMI reporting the min/max bandwidth as the number of links between peers, PCIe will report the min/max bandwidth as the number of supported lanes.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 24 ++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  3 +++
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c      |  3 +++
 3 files changed, 30 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +24 -0
index c84989eda8eb..99c662b70519 100644
@@ -568,6 +568,30 @@ uint8_t amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *sr
 	return  (uint8_t)ret;
 }
 
+uint32_t amdgpu_amdkfd_get_pcie_min_lanes(struct kgd_dev *dev)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)dev;
+	int min_lane_shift = ffs(adev->pm.pcie_mlw_mask >>
+				CAIL_PCIE_LINK_WIDTH_SUPPORT_SHIFT) - 1;
+
+	if (min_lane_shift < 0)
+		return 0;
+
+	return 1UL << min_lane_shift;
+}
+
+uint32_t amdgpu_amdkfd_get_pcie_max_lanes(struct kgd_dev *dev)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)dev;
+	int max_lane_shift = fls(adev->pm.pcie_mlw_mask >>
+				CAIL_PCIE_LINK_WIDTH_SUPPORT_SHIFT) - 1;
+
+	if (max_lane_shift < 0)
+		return 0;
+
+	return 1UL << max_lane_shift;
+}
+
 uint64_t amdgpu_amdkfd_get_mmio_remap_phys_addr(struct kgd_dev *kgd)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +3 -0
index 20e4bfce62be..88322c72a43d 100644
@@ -31,6 +31,7 @@
 #include <linux/workqueue.h>
 #include <kgd_kfd_interface.h>
 #include <drm/ttm/ttm_execbuf_util.h>
+#include "amd_pcie.h"
 #include "amdgpu_sync.h"
 #include "amdgpu_vm.h"
 
@@ -227,6 +228,8 @@ uint32_t amdgpu_amdkfd_get_asic_rev_id(struct kgd_dev *kgd);
 int amdgpu_amdkfd_get_noretry(struct kgd_dev *kgd);
 uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct kgd_dev *dst, struct kgd_dev *src);
 uint8_t amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *src);
+uint32_t amdgpu_amdkfd_get_pcie_min_lanes(struct kgd_dev *dev);
+uint32_t amdgpu_amdkfd_get_pcie_max_lanes(struct kgd_dev *dev);
 
 /* Read user wptr from a specified user address space with page fault
  * disabled. The memory must be pinned and mapped to the hardware when
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +3 -0
index 75047b77649b..f70d69035fe7 100644
@@ -1036,6 +1036,7 @@ static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
 			props->max_latency = iolink->maximum_latency;
 			props->min_bandwidth = iolink->minimum_bandwidth;
 			props->max_bandwidth = iolink->maximum_bandwidth;
+
 			props->rec_transfer_size =
 					iolink->recommended_transfer_size;
 
@@ -1993,6 +1994,8 @@ static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size,
 		sub_type_hdr->maximum_bandwidth = 1;
 	} else {
 		sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_PCIEXPRESS;
+		sub_type_hdr->minimum_bandwidth = amdgpu_amdkfd_get_pcie_min_lanes(kdev->kgd);
+		sub_type_hdr->maximum_bandwidth = amdgpu_amdkfd_get_pcie_max_lanes(kdev->kgd);
 	}
 
 	sub_type_hdr->proximity_domain_from = proximity_domain;
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#4 lore raw

RE: [PATCH 3/4] drm/amdkfd: report pcie bandwidth as number of lanes

[AMD Official Use Only]

Ping on series.
Note Patch 4 can be dropped. Runtime doesn't require an extra flag to determine direct connections.

Thanks,

Jon

Quoted 109 lines

-----Original Message-----
From: Kim, Jonathan <[email protected]>
Sent: Monday, June 21, 2021 3:24 PM
To: [email protected]
Cc: Zhang, Hawking <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>
Subject: [PATCH 3/4] drm/amdkfd: report pcie bandwidth as number of lanes

Similar to xGMI reporting the min/max bandwidth as the number of links between peers, PCIe will report the min/max bandwidth as the number of supported lanes.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 24
++++++++++++++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  3 +++
 drivers/gpu/drm/amd/amdkfd/kfd_crat.c      |  3 +++
 3 files changed, 30 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +0 -0
index c84989eda8eb..99c662b70519 100644
@@ -568,6 +568,30 @@ uint8_t

amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *sr

      return  (uint8_t)ret;

}

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +22 -0
+uint32_t amdgpu_amdkfd_get_pcie_min_lanes(struct kgd_dev *dev) {
+     struct amdgpu_device *adev = (struct amdgpu_device *)dev;
+     int min_lane_shift = ffs(adev->pm.pcie_mlw_mask >>
+                             CAIL_PCIE_LINK_WIDTH_SUPPORT_SHIFT) - 1;
+
+     if (min_lane_shift < 0)
+             return 0;
+
+     return 1UL << min_lane_shift;
+}
+
+uint32_t amdgpu_amdkfd_get_pcie_max_lanes(struct kgd_dev *dev) {
+     struct amdgpu_device *adev = (struct amdgpu_device *)dev;
+     int max_lane_shift = fls(adev->pm.pcie_mlw_mask >>
+                             CAIL_PCIE_LINK_WIDTH_SUPPORT_SHIFT) - 1;
+
+     if (max_lane_shift < 0)
+             return 0;
+
+     return 1UL << max_lane_shift;
+}
+
 uint64_t amdgpu_amdkfd_get_mmio_remap_phys_addr(struct kgd_dev
*kgd)  {
      struct amdgpu_device *adev = (struct amdgpu_device *)kgd; diff --git

a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h
index 20e4bfce62be..88322c72a43d 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +1 -0
@@ -31,6 +31,7 @@
 #include <linux/workqueue.h>
 #include <kgd_kfd_interface.h>
 #include <drm/ttm/ttm_execbuf_util.h>
+#include "amd_pcie.h"
 #include "amdgpu_sync.h"
 #include "amdgpu_vm.h"
 
@@ -227,6 +228,8 @@ uint32_t amdgpu_amdkfd_get_asic_rev_id(struct
 kgd_dev *kgd);  int amdgpu_amdkfd_get_noretry(struct kgd_dev *kgd);

uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct kgd_dev *dst, struct kgd_dev *src); uint8_t amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *src);

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +2 -0
+uint32_t amdgpu_amdkfd_get_pcie_min_lanes(struct kgd_dev *dev);
+uint32_t amdgpu_amdkfd_get_pcie_max_lanes(struct kgd_dev *dev);
 
 /* Read user wptr from a specified user address space with page fault
  * disabled. The memory must be pinned and mapped to the hardware

when diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_crat.c b/drivers/gpu/drm/amd/amdkfd/kfd_crat.c
index 75047b77649b..f70d69035fe7 100644

drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -0
@@ -1036,6 +1036,7 @@ static int kfd_parse_subtype_iolink(struct
 crat_subtype_iolink *iolink,
                      props->max_latency = iolink->maximum_latency;
                      props->min_bandwidth = iolink-
 >minimum_bandwidth;
                      props->max_bandwidth = iolink-
 >maximum_bandwidth;
+
                      props->rec_transfer_size =
                                      iolink->recommended_transfer_size;
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +3 -1
@@ -1993,6 +1994,8 @@ static int kfd_fill_gpu_direct_io_link_to_cpu(int
 *avail_size,
              sub_type_hdr->maximum_bandwidth = 1;
      } else {
              sub_type_hdr->io_interface_type =
 CRAT_IOLINK_TYPE_PCIEXPRESS;
+             sub_type_hdr->minimum_bandwidth =
 amdgpu_amdkfd_get_pcie_min_lanes(kdev->kgd);
+             sub_type_hdr->maximum_bandwidth =
+amdgpu_amdkfd_get_pcie_max_lanes(kdev->kgd);
      }
 
      sub_type_hdr->proximity_domain_from = proximity_domain;
--
Quoted 1 line

2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

maintainer
#5 lore raw

Re: [PATCH 3/4] drm/amdkfd: report pcie bandwidth as number of lanes

In reply to Jonathan Kim
Quoted 80 lines · Jonathan Kim

Similar to xGMI reporting the min/max bandwidth as the number of links between peers, PCIe will report the min/max bandwidth as the number of supported lanes.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 24 ++++++++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h |  3 +++
  drivers/gpu/drm/amd/amdkfd/kfd_crat.c      |  3 +++
  3 files changed, 30 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c +24 -0
index c84989eda8eb..99c662b70519 100644
@@ -568,6 +568,30 @@ uint8_t amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *sr
  	return  (uint8_t)ret;
  }
 
+uint32_t amdgpu_amdkfd_get_pcie_min_lanes(struct kgd_dev *dev)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)dev;
+	int min_lane_shift = ffs(adev->pm.pcie_mlw_mask >>
+				CAIL_PCIE_LINK_WIDTH_SUPPORT_SHIFT) - 1;
+
+	if (min_lane_shift < 0)
+		return 0;
+
+	return 1UL << min_lane_shift;
+}
+
+uint32_t amdgpu_amdkfd_get_pcie_max_lanes(struct kgd_dev *dev)
+{
+	struct amdgpu_device *adev = (struct amdgpu_device *)dev;
+	int max_lane_shift = fls(adev->pm.pcie_mlw_mask >>
+				CAIL_PCIE_LINK_WIDTH_SUPPORT_SHIFT) - 1;
+
+	if (max_lane_shift < 0)
+		return 0;
+
+	return 1UL << max_lane_shift;
+}
+
  uint64_t amdgpu_amdkfd_get_mmio_remap_phys_addr(struct kgd_dev *kgd)
  {
  	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.h +3 -0
index 20e4bfce62be..88322c72a43d 100644
@@ -31,6 +31,7 @@
  #include <linux/workqueue.h>
  #include <kgd_kfd_interface.h>
  #include <drm/ttm/ttm_execbuf_util.h>
+#include "amd_pcie.h"
  #include "amdgpu_sync.h"
  #include "amdgpu_vm.h"
 
@@ -227,6 +228,8 @@ uint32_t amdgpu_amdkfd_get_asic_rev_id(struct kgd_dev *kgd);
  int amdgpu_amdkfd_get_noretry(struct kgd_dev *kgd);
  uint8_t amdgpu_amdkfd_get_xgmi_hops_count(struct kgd_dev *dst, struct kgd_dev *src);
  uint8_t amdgpu_amdkfd_get_xgmi_num_links(struct kgd_dev *dst, struct kgd_dev *src);
+uint32_t amdgpu_amdkfd_get_pcie_min_lanes(struct kgd_dev *dev);
+uint32_t amdgpu_amdkfd_get_pcie_max_lanes(struct kgd_dev *dev);
 
  /* Read user wptr from a specified user address space with page fault
   * disabled. The memory must be pinned and mapped to the hardware when
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +1 -0
index 75047b77649b..f70d69035fe7 100644
@@ -1036,6 +1036,7 @@ static int kfd_parse_subtype_iolink(struct crat_subtype_iolink *iolink,
  			props->max_latency = iolink->maximum_latency;
  			props->min_bandwidth = iolink->minimum_bandwidth;
  			props->max_bandwidth = iolink->maximum_bandwidth;
+
  			props->rec_transfer_size =
  					iolink->recommended_transfer_size;
 

drivers/gpu/drm/amd/amdkfd/kfd_crat.c static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size, · line 1998

Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +2 -0
@@ -1993,6 +1994,8 @@ static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size,
  		sub_type_hdr->maximum_bandwidth = 1;
  	} else {
  		sub_type_hdr->io_interface_type = CRAT_IOLINK_TYPE_PCIEXPRESS;
+		sub_type_hdr->minimum_bandwidth = amdgpu_amdkfd_get_pcie_min_lanes(kdev->kgd);
+		sub_type_hdr->maximum_bandwidth = amdgpu_amdkfd_get_pcie_max_lanes(kdev->kgd);

Similar to XGMI, I did not mean to directly report the number of lanes here. Instead, used it to calculate the actual bandwidth in MB/s.

Regards,
  Felix

drivers/gpu/drm/amd/amdkfd/kfd_crat.c static int kfd_fill_gpu_direct_io_link_to_cpu(int *avail_size, · line 2001

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_crat.c +0 -0
  	}
 
  	sub_type_hdr->proximity_domain_from = proximity_domain;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#6 lore raw

PATCH 4/4 drm/amdkfd: add direct link flag to link properties

In reply to Jonathan Kim

Flag peers as a direct link if over PCIe or over xGMI if they are adjacent in the hive.

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.h     |  3 ++-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +2 -1
index d1f6de5edfb9..0d661d60ece6 100644
@@ -232,8 +232,9 @@ struct crat_subtype_ccompute {
 #define CRAT_IOLINK_FLAGS_NO_ATOMICS_32_BIT	(1 << 2)
 #define CRAT_IOLINK_FLAGS_NO_ATOMICS_64_BIT	(1 << 3)
 #define CRAT_IOLINK_FLAGS_NO_PEER_TO_PEER_DMA	(1 << 4)
+#define CRAT_IOLINK_FLAGS_DIRECT_LINK		(1 << 5)
 #define CRAT_IOLINK_FLAGS_BI_DIRECTIONAL 	(1 << 31)
-#define CRAT_IOLINK_FLAGS_RESERVED_MASK		0x7fffffe0
+#define CRAT_IOLINK_FLAGS_RESERVED_MASK		0x7fffffc0
 
 /*
  * IO interface types
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +11 -0
index b1ce072aa20b..037fa12ac1bc 100644
@@ -1244,6 +1244,15 @@ static void kfd_set_iolink_non_coherent(struct kfd_topology_device *to_dev,
 	}
 }
 
+static void kfd_set_iolink_direct_link(struct kfd_topology_device *dev,
+					struct kfd_iolink_properties *link)
+{
+	if (link->iolink_type == CRAT_IOLINK_TYPE_PCIEXPRESS ||
+			(link->iolink_type == CRAT_IOLINK_TYPE_XGMI &&
+							link->max_bandwidth))
+		link->flags |= CRAT_IOLINK_FLAGS_DIRECT_LINK;
+}
+
 static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)
 {
 	struct kfd_iolink_properties *link, *inbound_link;
@@ -1256,6 +1265,7 @@ static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)
 	list_for_each_entry(link, &dev->io_link_props, list) {
 		link->flags = CRAT_IOLINK_FLAGS_ENABLED;
 		kfd_set_iolink_no_atomics(dev, NULL, link);
+		kfd_set_iolink_direct_link(dev, link);
 		peer_dev = kfd_topology_device_by_proximity_domain(
 				link->node_to);
 
@@ -1270,6 +1280,7 @@ static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)
 			inbound_link->flags = CRAT_IOLINK_FLAGS_ENABLED;
 			kfd_set_iolink_no_atomics(peer_dev, dev, inbound_link);
 			kfd_set_iolink_non_coherent(peer_dev, link, inbound_link);
+			kfd_set_iolink_direct_link(peer_dev, inbound_link);
 		}
 	}
 }
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#7 lore raw

RE: [PATCH 4/4] drm/amdkfd: add direct link flag to link properties

[AMD Official Use Only]

This series Acked-by: Harish Kasiviswanathan <[email protected]>

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Jonathan Kim
Sent: Monday, June 21, 2021 3:24 PM
To: [email protected]
Cc: Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Zhang, Hawking <[email protected]>
Subject: [PATCH 4/4] drm/amdkfd: add direct link flag to link properties

Flag peers as a direct link if over PCIe or over xGMI if they are adjacent in the hive.

---
 drivers/gpu/drm/amd/amdkfd/kfd_crat.h     |  3 ++-
 drivers/gpu/drm/amd/amdkfd/kfd_topology.c | 11 +++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_crat.h +2 -1
index d1f6de5edfb9..0d661d60ece6 100644
@@ -232,8 +232,9 @@ struct crat_subtype_ccompute {
 #define CRAT_IOLINK_FLAGS_NO_ATOMICS_32_BIT	(1 << 2)
 #define CRAT_IOLINK_FLAGS_NO_ATOMICS_64_BIT	(1 << 3)
 #define CRAT_IOLINK_FLAGS_NO_PEER_TO_PEER_DMA	(1 << 4)
+#define CRAT_IOLINK_FLAGS_DIRECT_LINK		(1 << 5)
 #define CRAT_IOLINK_FLAGS_BI_DIRECTIONAL 	(1 << 31)
-#define CRAT_IOLINK_FLAGS_RESERVED_MASK		0x7fffffe0
+#define CRAT_IOLINK_FLAGS_RESERVED_MASK		0x7fffffc0
 
 /*
  * IO interface types
drivers/gpu/drm/amd/amdkfd/kfd_topology.c +7 -0
index b1ce072aa20b..037fa12ac1bc 100644
@@ -1244,6 +1244,15 @@ static void kfd_set_iolink_non_coherent(struct kfd_topology_device *to_dev,
 	}
 }
 
+static void kfd_set_iolink_direct_link(struct kfd_topology_device *dev,
+					struct kfd_iolink_properties *link) {
+	if (link->iolink_type == CRAT_IOLINK_TYPE_PCIEXPRESS ||
+			(link->iolink_type == CRAT_IOLINK_TYPE_XGMI &&
+							link->max_bandwidth))
+		link->flags |= CRAT_IOLINK_FLAGS_DIRECT_LINK; }
+
 static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)  {
 	struct kfd_iolink_properties *link, *inbound_link; @@ -1256,6 +1265,7 @@ static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)
 	list_for_each_entry(link, &dev->io_link_props, list) {

link->flags = CRAT_IOLINK_FLAGS_ENABLED; kfd_set_iolink_no_atomics(dev, NULL, link);
+ kfd_set_iolink_direct_link(dev, link);
peer_dev = kfd_topology_device_by_proximity_domain(
link->node_to);

@@ -1270,6 +1280,7 @@ static void kfd_fill_iolink_non_crat_info(struct kfd_topology_device *dev)
inbound_link->flags = CRAT_IOLINK_FLAGS_ENABLED; kfd_set_iolink_no_atomics(peer_dev, dev, inbound_link); kfd_set_iolink_non_coherent(peer_dev, link, inbound_link);
+ kfd_set_iolink_direct_link(peer_dev, inbound_link);
}
}
}
--
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7Charish.kasiviswanathan%40amd.com%7C92cd10a23764408da0ec08d934ea2680%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637599002557866754%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=utRekyrx5G9DD4TSayfxKwLFWv%2FnFlgzSErE7m6zdEw%3D&amp;reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx