From b14d1ca543fcfdafa3fa3c765fc539e0ee09ba5f Mon Sep 17 00:00:00 2001 From: Maisam Arif Date: Wed, 25 Oct 2023 17:13:03 -0500 Subject: [PATCH] SWDEV-410051 - Updates to board_info struct & CLI Signed-off-by: Maisam Arif Change-Id: I8735d8965140ee5da0c35106b388af1dca87ec71 [ROCm/amdsmi commit: 2b4637ff9f3e3c5ea6f529f146f30c0e0b847946] --- .../amdsmi/example/amd_smi_drm_example.cc | 6 ++- .../amdsmi/example/amd_smi_nodrm_example.cc | 6 ++- projects/amdsmi/include/amd_smi/amdsmi.h | 3 +- projects/amdsmi/py-interface/README.md | 10 +++-- .../amdsmi/py-interface/amdsmi_interface.py | 2 +- .../amdsmi/py-interface/amdsmi_wrapper.py.in | 24 +++++------ projects/amdsmi/rocm_smi/src/rocm_smi.cc | 1 - projects/amdsmi/src/amd_smi/amd_smi.cc | 7 +--- projects/amdsmi/src/amd_smi/amd_smi_utils.cc | 40 ++++++++++++------- 9 files changed, 55 insertions(+), 44 deletions(-) diff --git a/projects/amdsmi/example/amd_smi_drm_example.cc b/projects/amdsmi/example/amd_smi_drm_example.cc index 7b6997404b..9dd5f5562d 100644 --- a/projects/amdsmi/example/amd_smi_drm_example.cc +++ b/projects/amdsmi/example/amd_smi_drm_example.cc @@ -619,9 +619,11 @@ int main() { std::cout << "\tdevice [" << j << "]\n\t\tProduct name: " << board_info.product_name << "\n" - << "\t\tProduct number: " << board_info.product_serial + << "\t\tModel Number: " << board_info.model_number << "\n" - << "\t\tSerial number: " << board_info.serial_number + << "\t\tBoard Serial: " << board_info.product_serial + << "\n" + << "\t\tManufacturer Name: " << board_info.manufacturer_name << "\n\n"; // Get temperature diff --git a/projects/amdsmi/example/amd_smi_nodrm_example.cc b/projects/amdsmi/example/amd_smi_nodrm_example.cc index 3b4adce76a..987c8c9225 100644 --- a/projects/amdsmi/example/amd_smi_nodrm_example.cc +++ b/projects/amdsmi/example/amd_smi_nodrm_example.cc @@ -302,9 +302,11 @@ int main() { std::cout << "\tdevice [" << j << "]\n\t\tProduct name: " << board_info.product_name << "\n" - << "\t\tProduct number: " << board_info.product_serial + << "\t\tModel Number: " << board_info.model_number << "\n" - << "\t\tSerial number: " << board_info.serial_number + << "\t\tBoard Serial: " << board_info.product_serial + << "\n" + << "\t\tManufacturer Name: " << board_info.manufacturer_name << "\n\n"; // Get temperature diff --git a/projects/amdsmi/include/amd_smi/amdsmi.h b/projects/amdsmi/include/amd_smi/amdsmi.h index c8da0b4502..716d307682 100644 --- a/projects/amdsmi/include/amd_smi/amdsmi.h +++ b/projects/amdsmi/include/amd_smi/amdsmi.h @@ -501,13 +501,12 @@ typedef struct { } amdsmi_driver_info_t; typedef struct { - uint64_t serial_number; bool is_master; char model_number[AMDSMI_NORMAL_STRING_LENGTH]; char product_serial[AMDSMI_NORMAL_STRING_LENGTH]; char fru_id[AMDSMI_NORMAL_STRING_LENGTH]; - char product_name[AMDSMI_PRODUCT_NAME_LENGTH]; char manufacturer_name[AMDSMI_NORMAL_STRING_LENGTH]; + char product_name[AMDSMI_PRODUCT_NAME_LENGTH]; } amdsmi_board_info_t; typedef struct { diff --git a/projects/amdsmi/py-interface/README.md b/projects/amdsmi/py-interface/README.md index 55f36ba0eb..70c4419924 100644 --- a/projects/amdsmi/py-interface/README.md +++ b/projects/amdsmi/py-interface/README.md @@ -2,7 +2,7 @@ ## Requirements -* python 3.6 64-bit +* python 3.7+ 64-bit * driver must be loaded for amdsmi_init() to pass ## Overview @@ -998,8 +998,10 @@ Output: Dictionary with fields correctable and uncorrectable Field | Description ---|--- -`serial_number` | Board serial number +`model_number` | Board serial number `product_serial` | Product serial +`fru_id` | FRU ID +`manufacturer_name` | Manufacturer name `product_name` | Product name Exceptions that can be thrown by `amdsmi_get_gpu_board_info` function: @@ -1014,8 +1016,10 @@ Example: try: device = amdsmi_get_processor_handle_from_bdf("0000:23.00.0") board_info = amdsmi_get_gpu_board_info(device) - print(board_info["serial_number"]) + print(board_info["model_number"]) print(board_info["product_serial"]) + print(board_info["fru_id"]) + print(board_info["manufacturer_name"]) print(board_info["product_name"]) except AmdSmiException as e: print(e) diff --git a/projects/amdsmi/py-interface/amdsmi_interface.py b/projects/amdsmi/py-interface/amdsmi_interface.py index 1c3d6ec1e7..97d4dbc269 100644 --- a/projects/amdsmi/py-interface/amdsmi_interface.py +++ b/projects/amdsmi/py-interface/amdsmi_interface.py @@ -1147,7 +1147,7 @@ def amdsmi_get_gpu_board_info( return { "model_number": board_info.model_number.decode("utf-8").strip(), - "product_serial": board_info.serial_number, + "product_serial": board_info.product_serial.decode("utf-8").strip(), "fru_id": board_info.fru_id.decode("utf-8").strip(), "manufacturer_name" : board_info.manufacturer_name.decode("utf-8").strip(), "product_name": board_info.product_name.decode("utf-8").strip() diff --git a/projects/amdsmi/py-interface/amdsmi_wrapper.py.in b/projects/amdsmi/py-interface/amdsmi_wrapper.py.in index a7a16ce2de..18576d77fc 100644 --- a/projects/amdsmi/py-interface/amdsmi_wrapper.py.in +++ b/projects/amdsmi/py-interface/amdsmi_wrapper.py.in @@ -840,14 +840,12 @@ class struct_amdsmi_board_info_t(Structure): struct_amdsmi_board_info_t._pack_ = 1 # source:False struct_amdsmi_board_info_t._fields_ = [ - ('serial_number', ctypes.c_uint64), ('is_master', ctypes.c_bool), ('model_number', ctypes.c_char * 32), ('product_serial', ctypes.c_char * 32), ('fru_id', ctypes.c_char * 32), - ('product_name', ctypes.c_char * 128), ('manufacturer_name', ctypes.c_char * 32), - ('PADDING_0', ctypes.c_ubyte * 7), + ('product_name', ctypes.c_char * 128), ] amdsmi_board_info_t = struct_amdsmi_board_info_t @@ -894,6 +892,16 @@ amdsmi_process_handle_t = ctypes.c_uint32 class struct_amdsmi_proc_info_t(Structure): pass +class struct_engine_usage_(Structure): + pass + +struct_engine_usage_._pack_ = 1 # source:False +struct_engine_usage_._fields_ = [ + ('gfx', ctypes.c_uint64), + ('enc', ctypes.c_uint64), + ('reserved', ctypes.c_uint32 * 12), +] + class struct_memory_usage_(Structure): pass @@ -905,16 +913,6 @@ struct_memory_usage_._fields_ = [ ('reserved', ctypes.c_uint32 * 10), ] -class struct_engine_usage_(Structure): - pass - -struct_engine_usage_._pack_ = 1 # source:False -struct_engine_usage_._fields_ = [ - ('gfx', ctypes.c_uint64), - ('enc', ctypes.c_uint64), - ('reserved', ctypes.c_uint32 * 12), -] - struct_amdsmi_proc_info_t._pack_ = 1 # source:False struct_amdsmi_proc_info_t._fields_ = [ ('name', ctypes.c_char * 32), diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi.cc b/projects/amdsmi/rocm_smi/src/rocm_smi.cc index 6fe0c41d26..752e87da0d 100755 --- a/projects/amdsmi/rocm_smi/src/rocm_smi.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi.cc @@ -3969,7 +3969,6 @@ rsmi_status_t rsmi_dev_serial_number_get(uint32_t dv_ind, if (ret != RSMI_STATUS_SUCCESS) { return ret; } - uint32_t ln = static_cast(val_str.copy(serial_num, len)); serial_num[std::min(len - 1, ln)] = '\0'; diff --git a/projects/amdsmi/src/amd_smi/amd_smi.cc b/projects/amdsmi/src/amd_smi/amd_smi.cc index 145f4e639b..66088cd7e2 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi.cc @@ -466,15 +466,10 @@ amdsmi_status_t amdsmi_get_gpu_board_info(amdsmi_processor_handle processor_hand status = rsmi_wrapper(rsmi_dev_name_get, processor_handle, board_info->product_name, AMDSMI_PRODUCT_NAME_LENGTH); - if (board_info->product_serial[0] == '\0') { - status = rsmi_wrapper(rsmi_dev_serial_number_get, processor_handle, + status = rsmi_wrapper(rsmi_dev_serial_number_get, processor_handle, board_info->product_serial, AMDSMI_NORMAL_STRING_LENGTH); - } } - // Get FRU ID - // Get manufacturer name - return AMDSMI_STATUS_SUCCESS; } diff --git a/projects/amdsmi/src/amd_smi/amd_smi_utils.cc b/projects/amdsmi/src/amd_smi/amd_smi_utils.cc index 8aef5c8dc1..d733d0b031 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi_utils.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi_utils.cc @@ -116,29 +116,41 @@ amdsmi_status_t smi_amdgpu_get_board_info(amd::smi::AMDSmiGPUDevice* device, amd return AMDSMI_STATUS_NOT_SUPPORTED; } SMIGPUDEVICE_MUTEX(device->get_mutex()) - std::string product_name_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/product_name"); - std::string product_number_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/product_number"); - std::string serial_number_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/serial_number"); + std::string model_number_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/product_number"); + std::string product_serial_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/serial_number"); + std::string fru_id_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/fru_id"); + std::string manufacturer_name_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/manufacturer"); + std::string product_name_path = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/product_name"); FILE *fp; - fp = fopen(product_name_path.c_str(), "rb"); - if (fp) { - fgets(info->product_name, sizeof(info->product_name), fp); - fclose(fp); - } - - - fp = fopen(product_number_path.c_str(), "rb"); + fp = fopen(model_number_path.c_str(), "rb"); if (fp) { fgets(info->model_number, sizeof(info->model_number), fp); fclose(fp); } - - fp = fopen(serial_number_path.c_str(), "rb"); + fp = fopen(product_serial_path.c_str(), "rb"); if (fp) { - fscanf(fp, "%lx", &info->product_serial); + fgets(info->product_serial, sizeof(info->product_serial), fp); + fclose(fp); + } + + fp = fopen(fru_id_path.c_str(), "rb"); + if (fp) { + fgets(info->fru_id, sizeof(info->fru_id), fp); + fclose(fp); + } + + fp = fopen(manufacturer_name_path.c_str(), "rb"); + if (fp) { + fgets(info->manufacturer_name, sizeof(info->manufacturer_name), fp); + fclose(fp); + } + + fp = fopen(product_name_path.c_str(), "rb"); + if (fp) { + fgets(info->product_name, sizeof(info->product_name), fp); fclose(fp); }