From a1c2a246b1e19f9c8801d76970d549ea38212d77 Mon Sep 17 00:00:00 2001 From: "Bill(Shuzhou) Liu" Date: Thu, 13 Apr 2023 12:34:30 -0500 Subject: [PATCH] Crash if no hwmon sysfs Return NOT_SUPPORTED if no hwmon sysfs. Change-Id: I8f4bea0d74619150aee7dfc21fe62d24018e2994 [ROCm/amdsmi commit: b39a56fc526545173803e220c2b35d048995a658] --- projects/amdsmi/README.md | 2 +- projects/amdsmi/rocm_smi/src/rocm_smi.cc | 25 +++++++++++++------ .../amdsmi/rocm_smi/src/rocm_smi_device.cc | 3 +++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/projects/amdsmi/README.md b/projects/amdsmi/README.md index 468c18c754..ac7ec316c3 100755 --- a/projects/amdsmi/README.md +++ b/projects/amdsmi/README.md @@ -4,7 +4,7 @@ The AMD System Management Interface Library, or AMD SMI library, is a C library ## Supported platforms -At initial release, the AMD SMI library will support Linux bear metal and Linux virtual machine guest for AMD GPUs. In the future release, the library will be extended to support AMD EPYC™ CPUs. +At initial release, the AMD SMI library will support Linux bare metal and Linux virtual machine guest for AMD GPUs. In the future release, the library will be extended to support AMD EPYC™ CPUs. AMD SMI library can run on AMD ROCm supported platforms, please refer to [List of Supported Operating Systems and GPUs](https://docs.amd.com/bundle/ROCm-Getting-Started-Guide-v5.3/page/Introduction_to_ROCm_Getting_Started_Guide_for_Linux.html) diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi.cc b/projects/amdsmi/rocm_smi/src/rocm_smi.cc index 0339bb4246..12b8061a0c 100755 --- a/projects/amdsmi/rocm_smi/src/rocm_smi.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi.cc @@ -336,7 +336,9 @@ static rsmi_status_t get_dev_mon_value(amd::smi::MonitorTypes type, } GET_DEV_FROM_INDX - assert(dev->monitor() != nullptr); + if (dev->monitor() == nullptr) { + return RSMI_STATUS_NOT_SUPPORTED; + } std::string val_str; @@ -364,7 +366,9 @@ static rsmi_status_t get_dev_mon_value(amd::smi::MonitorTypes type, } GET_DEV_FROM_INDX - assert(dev->monitor() != nullptr); + if (dev->monitor() == nullptr) { + return RSMI_STATUS_NOT_SUPPORTED; + } std::string val_str; @@ -389,7 +393,9 @@ static rsmi_status_t set_dev_mon_value(amd::smi::MonitorTypes type, uint32_t dv_ind, uint32_t sensor_ind, T val) { GET_DEV_FROM_INDX - assert(dev->monitor() != nullptr); + if (dev->monitor() == nullptr) { + return RSMI_STATUS_NOT_SUPPORTED; + } int ret = dev->monitor()->writeMonitor(type, sensor_ind, std::to_string(val)); @@ -411,8 +417,9 @@ static rsmi_status_t get_power_mon_value(amd::smi::PowerMonTypes type, } std::shared_ptr dev = smi.devices()[dv_ind]; - assert(dev != nullptr); - assert(dev->monitor() != nullptr); + if (dev == nullptr || dev->monitor() == nullptr) { + return RSMI_STATUS_NOT_SUPPORTED; + } ret = dev->power_monitor()->readPowerValue(type, val); @@ -2223,7 +2230,9 @@ rsmi_dev_temp_metric_get(uint32_t dv_ind, uint32_t sensor_type, GET_DEV_FROM_INDX - assert(dev->monitor() != nullptr); + if (dev->monitor() == nullptr) { + return RSMI_STATUS_NOT_SUPPORTED; + } std::shared_ptr m = dev->monitor(); // getTempSensorIndex will throw an out of range exception if sensor_type is @@ -2281,7 +2290,9 @@ rsmi_dev_volt_metric_get(uint32_t dv_ind, rsmi_voltage_type_t sensor_type, GET_DEV_FROM_INDX - assert(dev->monitor() != nullptr); + if (dev->monitor() == nullptr) { + return RSMI_STATUS_NOT_SUPPORTED; + } std::shared_ptr m = dev->monitor(); // getVoltSensorIndex will throw an out of range exception if sensor_type is diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi_device.cc b/projects/amdsmi/rocm_smi/src/rocm_smi_device.cc index cd6956cad0..67b198ef83 100755 --- a/projects/amdsmi/rocm_smi/src/rocm_smi_device.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi_device.cc @@ -974,6 +974,9 @@ void Device::fillSupportedFuncs(void) { if (supported_funcs_.size() != 0) { return; } + if (monitor() == nullptr) { + return; + } std::map::const_iterator it = kDevFuncDependsMap.begin();