[SWDEV-530633] Use gpu_metric speed and BW for xgmi (#366)

The xgmi command was showing pcie bit rate and bandwidth instead of xgmi. Corrected the API to get xgmi data from gpu metric.
Added python API for amdsmi_get_link_metrics. Modified the amdsmi_link_metrics struct.
Added check to confirm non zero partition got xgmi command.

---------

Signed-off-by: Bindhiya Kanangot Balakrishnan <Bindhiya.KanangotBalakrishnan@amd.com>
Signed-off-by: Maisam Arif <Maisam.Arif@amd.com>
This commit is contained in:
Kanangot Balakrishnan, Bindhiya
2025-05-30 16:51:11 -05:00
committed by GitHub
parent 2e8aaf02c9
commit 2eff0b3764
7 changed files with 147 additions and 31 deletions
+1
View File
@@ -221,6 +221,7 @@ from .amdsmi_interface import amdsmi_get_gpu_subsystem_name
from .amdsmi_interface import amdsmi_topo_get_numa_node_number
from .amdsmi_interface import amdsmi_topo_get_link_weight
from .amdsmi_interface import amdsmi_get_minmax_bandwidth_between_processors
from .amdsmi_interface import amdsmi_get_link_metrics
from .amdsmi_interface import amdsmi_topo_get_link_type
from .amdsmi_interface import amdsmi_topo_get_p2p_status
from .amdsmi_interface import amdsmi_is_P2P_accessible
+35
View File
@@ -3099,6 +3099,41 @@ def amdsmi_get_minmax_bandwidth_between_processors(
return {"min_bandwidth": min_bandwidth.value, "max_bandwidth": max_bandwidth.value}
def amdsmi_get_link_metrics(processor_handle: amdsmi_wrapper.amdsmi_processor_handle):
if not isinstance(processor_handle, amdsmi_wrapper.amdsmi_processor_handle):
raise AmdSmiParameterException(
processor_handle, amdsmi_wrapper.amdsmi_processor_handle
)
link_metrics = amdsmi_wrapper.amdsmi_link_metrics_t()
_check_res(
amdsmi_wrapper.amdsmi_get_link_metrics(
processor_handle, ctypes.byref(link_metrics)
)
)
bdf = amdsmi_wrapper.amdsmi_bdf_t()
# TODO: Dummy BDF - to be replaced with destination BDF from xgmi_port_num when available
bdf.struct_amdsmi_bdf_t = amdsmi_wrapper.struct_amdsmi_bdf_t(0xFFFF, 0xFF, 0xFF, 0xF)
links = []
for i in range(AMDSMI_MAX_NUM_XGMI_LINKS):
link = link_metrics.links[i]
links.append({
"bdf": _format_bdf(bdf),
"link_type": link.link_type,
"read": link.read,
"write": link.write,
})
return {
"num_links": AMDSMI_MAX_NUM_XGMI_LINKS,
"bit_rate": link_metrics.bit_rate,
"max_bandwidth": link_metrics.max_bandwidth,
"links": links
}
def amdsmi_topo_get_link_type(
processor_handle_src: amdsmi_wrapper.amdsmi_processor_handle,
processor_handle_dst: amdsmi_wrapper.amdsmi_processor_handle,
+2 -2
View File
@@ -1153,8 +1153,6 @@ class struct__links(Structure):
struct__links._pack_ = 1 # source:False
struct__links._fields_ = [
('bdf', amdsmi_bdf_t),
('bit_rate', ctypes.c_uint32),
('max_bandwidth', ctypes.c_uint32),
('link_type', amdsmi_link_type_t),
('PADDING_0', ctypes.c_ubyte * 4),
('read', ctypes.c_uint64),
@@ -1165,6 +1163,8 @@ struct__links._fields_ = [
struct_amdsmi_link_metrics_t._pack_ = 1 # source:False
struct_amdsmi_link_metrics_t._fields_ = [
('num_links', ctypes.c_uint32),
('bit_rate', ctypes.c_uint32),
('max_bandwidth', ctypes.c_uint32),
('PADDING_0', ctypes.c_ubyte * 4),
('links', struct__links * 64),
('reserved', ctypes.c_uint64 * 7),