amdsmi: Adding Support to get hsmp Driver version

* amdsmi: Adding Support to get hsmp Driver version

Adding Support to fetch hsmp driver version from ESmi Interfaces.
Adding Support to fetch memory bandwidth per socket.

Signed-off-by: muthusamy <muthusamy.ramalingam@amd.com>
Este commit está contenido en:
Ramalingam, Muthusamy
2025-01-30 01:15:02 +05:30
cometido por GitHub
padre 21841f44a5
commit ced110dbb6
Se han modificado 7 ficheros con 246 adiciones y 49 borrados
+46
Ver fichero
@@ -4010,6 +4010,52 @@ except AmdSmiException as e:
print(e)
```
### amdsmi_get_threads_per_core
Description: Get number of threads per core.
Output: cpu family
Exceptions that can be thrown by `amdsmi_get_cpu_family` function:
* `AmdSmiLibraryException`
Example:
```python
try:
threads_per_core = amdsmi_get_threads_per_core()
print(threads_per_core)
except AmdSmiException as e:
print(e)
```
### amdsmi_get_cpu_hsmp_driver_version
Description: Get the HSMP Driver version.
Output: amdsmi HSMP Driver version
Exceptions that can be thrown by `amdsmi_get_cpu_hsmp_driver_version` function:
* `AmdSmiLibraryException`
Example:
```python
try:
processor_handles = amdsmi_get_cpusocket_handles()
if len(processor_handles) == 0:
print("No CPU sockets on machine")
else:
for processor in processor_handles:
version = amdsmi_get_cpu_hsmp_driver_version(processor)
print(version['major'])
print(version['minor'])
except AmdSmiException as e:
print(e)
```
### amdsmi_get_cpu_smu_fw_version
Description: Get the SMU Firmware version.
+21
Ver fichero
@@ -1685,6 +1685,14 @@ typedef struct {
#define AMDSMI_DEFAULT_VARIANT 0xFFFFFFFFFFFFFFFF
#ifdef ENABLE_ESMI_LIB
/**
* @brief This structure holds HSMP Driver version information.
*/
typedef struct {
uint8_t major; //!< Major version number
uint8_t minor; //!< Minor version number
} amdsmi_hsmp_driver_version_t;
/**
* @brief This structure holds SMU Firmware version information.
*/
@@ -5365,6 +5373,19 @@ amdsmi_status_t amdsmi_get_cpu_socket_energy(amdsmi_processor_handle processor_h
*/
amdsmi_status_t amdsmi_get_threads_per_core(uint32_t *threads_per_core);
/**
* @brief Get HSMP Driver Version.
*
* @platform{cpu_bm}
*
* @param[in] processor_handle Cpu socket which to query
* @param[in,out] amdsmi_hsmp_driver_ver - Input buffer to return the HSMP Driver version
*
* @return ::amdsmi_status_t | ::AMDSMI_STATUS_SUCCESS on success, non-zero on fail
*/
amdsmi_status_t amdsmi_get_cpu_hsmp_driver_version(amdsmi_processor_handle processor_handle,
amdsmi_hsmp_driver_version_t *amdsmi_hsmp_driver_ver);
/**
* @brief Get SMU Firmware Version.
*
+105 -46
Ver fichero
@@ -13,58 +13,65 @@
* HSMP Messages supported
*/
enum hsmp_message_ids {
HSMP_TEST = 1, /* 01h Increments input value by 1 */
HSMP_GET_SMU_VER, /* 02h SMU FW version */
HSMP_GET_PROTO_VER, /* 03h HSMP interface version */
HSMP_GET_SOCKET_POWER, /* 04h average package power consumption */
HSMP_TEST = 1, /* 01h Increments input value by 1 */
HSMP_GET_SMU_VER, /* 02h SMU FW version */
HSMP_GET_PROTO_VER, /* 03h HSMP interface version */
HSMP_GET_SOCKET_POWER, /* 04h average package power consumption */
HSMP_SET_SOCKET_POWER_LIMIT, /* 05h Set the socket power limit */
HSMP_GET_SOCKET_POWER_LIMIT, /* 06h Get current socket power limit */
HSMP_GET_SOCKET_POWER_LIMIT_MAX,/* 07h Get maximum socket power value */
HSMP_SET_BOOST_LIMIT, /* 08h Set a core maximum frequency limit */
HSMP_SET_BOOST_LIMIT, /* 08h Set a core maximum frequency limit */
HSMP_SET_BOOST_LIMIT_SOCKET, /* 09h Set socket maximum frequency level */
HSMP_GET_BOOST_LIMIT, /* 0Ah Get current frequency limit */
HSMP_GET_PROC_HOT, /* 0Bh Get PROCHOT status */
HSMP_SET_XGMI_LINK_WIDTH, /* 0Ch Set max and min width of xGMI Link */
HSMP_SET_DF_PSTATE, /* 0Dh Alter APEnable/Disable messages behavior */
HSMP_SET_AUTO_DF_PSTATE, /* 0Eh Enable DF P-State Performance Boost algorithm */
HSMP_GET_FCLK_MCLK, /* 0Fh Get FCLK and MEMCLK for current socket */
HSMP_GET_BOOST_LIMIT, /* 0Ah Get current frequency limit */
HSMP_GET_PROC_HOT, /* 0Bh Get PROCHOT status */
HSMP_SET_XGMI_LINK_WIDTH, /* 0Ch Set max and min width of xGMI Link */
HSMP_SET_DF_PSTATE, /* 0Dh Alter APEnable/Disable messages behavior */
HSMP_SET_AUTO_DF_PSTATE, /* 0Eh Enable DF P-State Performance Boost algorithm */
HSMP_GET_FCLK_MCLK, /* 0Fh Get FCLK and MEMCLK for current socket */
HSMP_GET_CCLK_THROTTLE_LIMIT, /* 10h Get CCLK frequency limit in socket */
HSMP_GET_C0_PERCENT, /* 11h Get average C0 residency in socket */
HSMP_SET_NBIO_DPM_LEVEL, /* 12h Set max/min LCLK DPM Level for a given NBIO */
HSMP_GET_NBIO_DPM_LEVEL, /* 13h Get LCLK DPM level min and max for a given NBIO */
HSMP_GET_DDR_BANDWIDTH, /* 14h Get theoretical maximum and current DDR Bandwidth */
HSMP_GET_TEMP_MONITOR, /* 15h Get socket temperature */
HSMP_GET_DIMM_TEMP_RANGE, /* 16h Get per-DIMM temperature range and refresh rate */
HSMP_GET_DIMM_POWER, /* 17h Get per-DIMM power consumption */
HSMP_GET_DIMM_THERMAL, /* 18h Get per-DIMM thermal sensors */
HSMP_GET_SOCKET_FREQ_LIMIT, /* 19h Get current active frequency per socket */
HSMP_GET_CCLK_CORE_LIMIT, /* 1Ah Get CCLK frequency limit per core */
HSMP_GET_RAILS_SVI, /* 1Bh Get SVI-based Telemetry for all rails */
HSMP_GET_SOCKET_FMAX_FMIN,/* 1Ch Get Fmax and Fmin per socket */
HSMP_GET_IOLINK_BANDWITH, /* 1Dh Get current bandwidth on IO Link */
HSMP_GET_XGMI_BANDWITH, /* 1Eh Get current bandwidth on xGMI Link */
HSMP_SET_GMI3_WIDTH, /* 1Fh Set max and min GMI3 Link width */
HSMP_SET_PCI_RATE, /* 20h Control link rate on PCIe devices */
HSMP_SET_POWER_MODE, /* 21h Select power efficiency profile policy */
HSMP_SET_PSTATE_MAX_MIN, /* 22h Set the max and min DF P-State */
HSMP_GET_METRIC_TABLE_VER,/* 23h Get metrics table version */
HSMP_GET_METRIC_TABLE, /* 24h Get metrics table */
HSMP_GET_C0_PERCENT, /* 11h Get average C0 residency in socket */
HSMP_SET_NBIO_DPM_LEVEL, /* 12h Set max/min LCLK DPM Level for a given NBIO */
HSMP_GET_NBIO_DPM_LEVEL, /* 13h Get LCLK DPM level min and max for a given NBIO */
HSMP_GET_DDR_BANDWIDTH, /* 14h Get theoretical maximum and current DDR Bandwidth */
HSMP_GET_TEMP_MONITOR, /* 15h Get socket temperature */
HSMP_GET_DIMM_TEMP_RANGE, /* 16h Get per-DIMM temperature range and refresh rate */
HSMP_GET_DIMM_POWER, /* 17h Get per-DIMM power consumption */
HSMP_GET_DIMM_THERMAL, /* 18h Get per-DIMM thermal sensors */
HSMP_GET_SOCKET_FREQ_LIMIT, /* 19h Get current active frequency per socket */
HSMP_GET_CCLK_CORE_LIMIT, /* 1Ah Get CCLK frequency limit per core */
HSMP_GET_RAILS_SVI, /* 1Bh Get SVI-based Telemetry for all rails */
HSMP_GET_SOCKET_FMAX_FMIN, /* 1Ch Get Fmax and Fmin per socket */
HSMP_GET_IOLINK_BANDWITH, /* 1Dh Get current bandwidth on IO Link */
HSMP_GET_XGMI_BANDWITH, /* 1Eh Get current bandwidth on xGMI Link */
HSMP_SET_GMI3_WIDTH, /* 1Fh Set max and min GMI3 Link width */
HSMP_SET_PCI_RATE, /* 20h Control link rate on PCIe devices */
HSMP_SET_POWER_MODE, /* 21h Select power efficiency profile policy */
HSMP_SET_PSTATE_MAX_MIN, /* 22h Set the max and min DF P-State */
HSMP_GET_METRIC_TABLE_VER, /* 23h Get metrics table version */
HSMP_GET_METRIC_TABLE, /* 24h Get metrics table */
HSMP_GET_METRIC_TABLE_DRAM_ADDR,/* 25h Get metrics table dram address */
HSMP_SET_XGMI_PSTATE_RANGE, /* 26h Set xGMI P-state range */
HSMP_CPU_RAIL_ISO_FREQ_POLICY, /* 27h Get/Set Cpu Iso frequency policy */
HSMP_DFC_ENABLE_CTRL, /* 28h Enable/Disable DF C-state */
HSMP_GET_RAPL_UNITS = 0x30, /* 30h Get scaling factor for energy */
HSMP_GET_RAPL_CORE_COUNTER, /* 31h Get core energy counter value */
HSMP_GET_RAPL_PACKAGE_COUNTER, /* 32h Get package energy counter value */
HSMP_MSG_ID_MAX,
};
struct hsmp_message {
__u32 msg_id; /* Message ID */
__u16 num_args; /* Number of input argument words in message */
__u16 response_sz; /* Number of expected output/response words */
__u32 args[HSMP_MAX_MSG_LEN]; /* argument/response buffer */
__u16 sock_ind; /* socket number */
__u32 msg_id; /* Message ID */
__u16 num_args; /* Number of input argument words in message */
__u16 response_sz; /* Number of expected output/response words */
__u32 args[HSMP_MAX_MSG_LEN];/* argument/response buffer */
__u16 sock_ind; /* socket number */
};
enum hsmp_msg_type {
HSMP_RSVD = -1,
HSMP_SET = 0,
HSMP_GET = 1,
HSMP_RSVD = -1,
HSMP_SET = 0,
HSMP_GET = 1,
HSMP_SET_GET = 2,
};
enum hsmp_proto_versions {
@@ -72,7 +79,8 @@ enum hsmp_proto_versions {
HSMP_PROTO_VER3,
HSMP_PROTO_VER4,
HSMP_PROTO_VER5,
HSMP_PROTO_VER6
HSMP_PROTO_VER6,
HSMP_PROTO_VER7
};
struct hsmp_msg_desc {
@@ -88,8 +96,7 @@ struct hsmp_msg_desc {
*
* Not supported messages would return -ENOMSG.
*/
static const struct hsmp_msg_desc hsmp_msg_desc_table[]
__attribute__((unused)) = {
static const struct hsmp_msg_desc hsmp_msg_desc_table[] = {
/* RESERVED */
{0, 0, HSMP_RSVD},
@@ -252,7 +259,7 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[]
/*
* HSMP_GET_CCLK_CORE_LIMIT, num_args = 1, response_sz = 1
* input: args[0] = apic id [31:0]
* input: args[0] = apic id of the core[31:0]
* output: args[0] = frequency in MHz[31:0]
*/
{1, 1, HSMP_GET},
@@ -297,10 +304,11 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[]
{1, 1, HSMP_SET},
/*
* HSMP_SET_POWER_MODE, num_args = 1, response_sz = 0
* input: args[0] = power efficiency mode[2:0]
* HSMP_SET_POWER_MODE, num_args = 1, response_sz = 0/1
* input: args[0] = set/get power mode[31] + power efficiency mode[2:0]
* output: args[0] = current power efficiency mode[2:0]
*/
{1, 0, HSMP_SET},
{1, 1, HSMP_SET_GET},
/*
* HSMP_SET_PSTATE_MAX_MIN, num_args = 1, response_sz = 0
@@ -325,6 +333,57 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[]
* output: args[1] = upper 32 bits of the address
*/
{0, 2, HSMP_GET},
/*
* HSMP_SET_XGMI_PSTATE_RANGE, num_args = 1, response_sz = 0
* input: args[0] = min xGMI p-state[15:8] + max xGMI state[7:0]
*/
{1, 0, HSMP_SET},
/*
* HSMP_CPU_RAIL_ISO_FREQ_POLICY, num_args = 1, response_sz = 1
* input: args[0] = set/get policy[31] +
* disable/enable independent control[0]
* output: args[0] = current policy[0]
*/
{1, 1, HSMP_SET_GET},
/*
* HSMP_DFC_ENABLE_CTRL, num_args = 1, response_sz = 1
* input: args[0] = set/get policy[31] + enable/disable DFC[0]
* output: args[0] = current policy[0]
*/
{1, 1, HSMP_SET_GET},
/* RESERVED(0x29-0x2f) */
{0, 0, HSMP_RSVD},
{0, 0, HSMP_RSVD},
{0, 0, HSMP_RSVD},
{0, 0, HSMP_RSVD},
{0, 0, HSMP_RSVD},
{0, 0, HSMP_RSVD},
{0, 0, HSMP_RSVD},
/*
* HSMP_GET_RAPL_UNITS, response_sz = 1
* output: args[0] = tu value[19:16] + esu value[12:8]
*/
{0, 1, HSMP_GET},
/*
* HSMP_GET_RAPL_CORE_COUNTER, num_args = 1, response_sz = 1
* input: args[0] = Apic id[15:0]
* output: args[0] = lower 32 bits of energy
* output: args[1] = upper 32 bits of energy
*/
{1, 2, HSMP_GET},
/*
* HSMP_GET_RAPL_PACKAGE_COUNTER, num_args = 0, response_sz = 1
* output: args[0] = lower 32 bits of energy
* output: args[1] = upper 32 bits of energy
*/
{0, 2, HSMP_GET},
};
/* Metrics table (supported only with proto version 6) */
+2
Ver fichero
@@ -39,6 +39,8 @@ try:
from .amdsmi_interface import amdsmi_get_cpu_smu_fw_version
from .amdsmi_interface import amdsmi_get_cpu_core_energy
from .amdsmi_interface import amdsmi_get_cpu_socket_energy
from .amdsmi_interface import amdsmi_get_threads_per_core
from .amdsmi_interface import amdsmi_get_cpu_hsmp_driver_version
from .amdsmi_interface import amdsmi_get_cpu_prochot_status
from .amdsmi_interface import amdsmi_get_cpu_fclk_mclk
from .amdsmi_interface import amdsmi_get_cpu_cclk_limit
+25
Ver fichero
@@ -826,6 +826,21 @@ def amdsmi_get_cpu_smu_fw_version(processor_handle: amdsmi_wrapper.amdsmi_proces
"smu_fw_major_ver_num": smu_fw.major
}
def amdsmi_get_cpu_hsmp_driver_version(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
)
hsmp_driver_version = amdsmi_wrapper.amdsmi_hsmp_driver_version_t()
_check_res(amdsmi_wrapper.amdsmi_get_cpu_hsmp_driver_version(processor_handle, hsmp_driver_version))
return {
"hsmp_driver_major_ver_num": hsmp_driver_version.major,
"hsmp_driver_minor_ver_num": hsmp_driver_version.minor,
}
def amdsmi_get_cpu_core_energy(
processor_handle: amdsmi_wrapper.amdsmi_processor_handle
) -> int:
@@ -860,6 +875,16 @@ def amdsmi_get_cpu_socket_energy(
return f"{float(penergy.value * pow(10, -6))} J"
def amdsmi_get_threads_per_core():
threads_per_core = ctypes.c_uint32()
_check_res(
amdsmi_wrapper.amdsmi_get_threads_per_core(
ctypes.byref(threads_per_core)
)
)
return threads_per_core.value
def amdsmi_get_cpu_prochot_status(
processor_handle: amdsmi_wrapper.amdsmi_processor_handle
) -> int:
+18 -2
Ver fichero
@@ -1989,6 +1989,16 @@ struct_amdsmi_topology_nearest_t._fields_ = [
]
amdsmi_topology_nearest_t = struct_amdsmi_topology_nearest_t
class struct_amdsmi_hsmp_driver_version_t(Structure):
pass
struct_amdsmi_hsmp_driver_version_t._pack_ = 1 # source:False
struct_amdsmi_hsmp_driver_version_t._fields_ = [
('major', ctypes.c_ubyte),
('minor', ctypes.c_ubyte),
]
amdsmi_hsmp_driver_version_t = struct_amdsmi_hsmp_driver_version_t
class struct_amdsmi_smu_fw_version_t(Structure):
pass
@@ -2553,6 +2563,9 @@ amdsmi_get_cpu_socket_energy.argtypes = [amdsmi_processor_handle, ctypes.POINTER
amdsmi_get_threads_per_core = _libraries['libamd_smi.so'].amdsmi_get_threads_per_core
amdsmi_get_threads_per_core.restype = amdsmi_status_t
amdsmi_get_threads_per_core.argtypes = [ctypes.POINTER(ctypes.c_uint32)]
amdsmi_get_cpu_hsmp_driver_version = _libraries['libamd_smi.so'].amdsmi_get_cpu_hsmp_driver_version
amdsmi_get_cpu_hsmp_driver_version.restype = amdsmi_status_t
amdsmi_get_cpu_hsmp_driver_version.argtypes = [amdsmi_processor_handle, ctypes.POINTER(struct_amdsmi_hsmp_driver_version_t)]
amdsmi_get_cpu_smu_fw_version = _libraries['libamd_smi.so'].amdsmi_get_cpu_smu_fw_version
amdsmi_get_cpu_smu_fw_version.restype = amdsmi_status_t
amdsmi_get_cpu_smu_fw_version.argtypes = [amdsmi_processor_handle, ctypes.POINTER(struct_amdsmi_smu_fw_version_t)]
@@ -2922,6 +2935,7 @@ __all__ = \
'amdsmi_get_cpu_dimm_temp_range_and_refresh_rate',
'amdsmi_get_cpu_dimm_thermal_sensor', 'amdsmi_get_cpu_family',
'amdsmi_get_cpu_fclk_mclk', 'amdsmi_get_cpu_handles',
'amdsmi_get_cpu_hsmp_driver_version',
'amdsmi_get_cpu_hsmp_proto_ver', 'amdsmi_get_cpu_model',
'amdsmi_get_cpu_prochot_status',
'amdsmi_get_cpu_pwr_svi_telemetry_all_rails',
@@ -2996,8 +3010,9 @@ __all__ = \
'amdsmi_gpu_cache_info_t', 'amdsmi_gpu_control_counter',
'amdsmi_gpu_counter_group_supported', 'amdsmi_gpu_create_counter',
'amdsmi_gpu_destroy_counter', 'amdsmi_gpu_metrics_t',
'amdsmi_gpu_read_counter', 'amdsmi_gpu_validate_ras_eeprom',
'amdsmi_gpu_xcp_metrics_t', 'amdsmi_gpu_xgmi_error_status',
'amdsmi_gpu_read_counter', 'amdsmi_gpu_xcp_metrics_t',
'amdsmi_gpu_xgmi_error_status', 'amdsmi_hsmp_driver_version_t',
'amdsmi_gpu_validate_ras_eeprom',
'amdsmi_hsmp_freqlimit_src_names', 'amdsmi_hsmp_metrics_table_t',
'amdsmi_init', 'amdsmi_init_flags_t',
'amdsmi_init_gpu_event_notification', 'amdsmi_io_bw_encoding_t',
@@ -3070,6 +3085,7 @@ __all__ = \
'struct_amdsmi_frequency_range_t', 'struct_amdsmi_fw_info_t',
'struct_amdsmi_gpu_cache_info_t', 'struct_amdsmi_gpu_metrics_t',
'struct_amdsmi_gpu_xcp_metrics_t',
'struct_amdsmi_hsmp_driver_version_t',
'struct_amdsmi_hsmp_metrics_table_t', 'struct_amdsmi_kfd_info_t',
'struct_amdsmi_link_id_bw_type_t', 'struct_amdsmi_link_metrics_t',
'struct_amdsmi_memory_partition_config_t',
+29 -1
Ver fichero
@@ -3831,6 +3831,27 @@ amdsmi_status_t amdsmi_get_cpu_hsmp_proto_ver(amdsmi_processor_handle processor_
return AMDSMI_STATUS_SUCCESS;
}
amdsmi_status_t amdsmi_get_cpu_hsmp_driver_version(amdsmi_processor_handle processor_handle,
amdsmi_hsmp_driver_version_t *amdsmi_hsmp_driver_ver)
{
amdsmi_status_t status;
struct hsmp_driver_version hsmp_driver_ver;
AMDSMI_CHECK_INIT();
if (processor_handle == nullptr)
return AMDSMI_STATUS_INVAL;
status = static_cast<amdsmi_status_t>(esmi_hsmp_driver_version_get(&hsmp_driver_ver));
if (status != AMDSMI_STATUS_SUCCESS)
return amdsmi_errno_to_esmi_status(status);
amdsmi_hsmp_driver_ver->major = hsmp_driver_ver.major;
amdsmi_hsmp_driver_ver->minor = hsmp_driver_ver.minor;
return AMDSMI_STATUS_SUCCESS;
}
amdsmi_status_t amdsmi_get_cpu_smu_fw_version(amdsmi_processor_handle processor_handle,
amdsmi_smu_fw_version_t *amdsmi_smu_fw)
{
@@ -4340,13 +4361,20 @@ amdsmi_status_t amdsmi_get_cpu_ddr_bw(amdsmi_processor_handle processor_handle,
{
amdsmi_status_t status;
struct ddr_bw_metrics ddr;
uint8_t sock_ind;
AMDSMI_CHECK_INIT();
if (processor_handle == nullptr)
return AMDSMI_STATUS_INVAL;
status = static_cast<amdsmi_status_t>(esmi_ddr_bw_get(&ddr));
amdsmi_status_t r = amdsmi_get_processor_info(processor_handle, SIZE, proc_id);
if (r != AMDSMI_STATUS_SUCCESS)
return r;
sock_ind = (uint8_t)std::stoi(proc_id, NULL, 0);
status = static_cast<amdsmi_status_t>(esmi_ddr_bw_get(sock_ind, &ddr));
if (status != AMDSMI_STATUS_SUCCESS)
return amdsmi_errno_to_esmi_status(status);