From c3a0ec4f9a9f711a71d05752750fb27ce4e1207c Mon Sep 17 00:00:00 2001 From: "Liu, Shuzhou (Bill)" Date: Thu, 27 Mar 2025 16:36:43 -0400 Subject: [PATCH] [SWDEV-524147] Patch for handling new ras filenames (#205) The code is changed to handle both original and ACA based ECC counters for backward compatibilities. Signed-off-by: Maisam Arif Co-authored-by: Maisam Arif [ROCm/amdsmi commit: 9b6e0432b2bd7e442a884500815048ab70f28c64] --- .../amdsmi/rocm_smi/src/rocm_smi_device.cc | 38 ++++++++++++++++++- projects/amdsmi/src/amd_smi/amd_smi_utils.cc | 7 +++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/projects/amdsmi/rocm_smi/src/rocm_smi_device.cc b/projects/amdsmi/rocm_smi/src/rocm_smi_device.cc index 80f89f08e3..ab81a76659 100644 --- a/projects/amdsmi/rocm_smi/src/rocm_smi_device.cc +++ b/projects/amdsmi/rocm_smi/src/rocm_smi_device.cc @@ -736,6 +736,17 @@ std::string Device::get_sys_file_path_by_type(DevInfoTypes type) const { return sysfs_path; } +// The fallback sysfs to handle backward compatibilities +static const std::map kDevFallbackFile = { + {kDevErrCntGFX, "ras/aca_gfx"}, + {kDevErrCntSDMA, "ras/aca_sdma"}, + {kDevErrCntUMC, "ras/aca_umc"}, + {kDevErrCntMMHUB, "ras/aca_mmhub"}, + {kDevErrCntPCIEBIF, "ras/aca_pcie_bif"}, + {kDevErrCntHDP, "ras/aca_hdp"}, + {kDevErrCntXGMIWAFL, "ras/aca_xgmi_wafl"}, +}; + template int Device::openSysfsFileStream(DevInfoTypes type, T *fs, const char *str) { auto sysfs_path = path_; @@ -769,6 +780,28 @@ int Device::openSysfsFileStream(DevInfoTypes type, T *fs, const char *str) { bool reg_file; int ret = isRegularFile(sysfs_path, ®_file); + + if (ret != 0 || !reg_file) { + // Handle specific types if the file does not exist + if (kDevFallbackFile.find(type) != kDevFallbackFile.end()) { + + sysfs_path = path_ + "/device/" + kDevFallbackFile.at(type); + DBG_FILE_ERROR(sysfs_path, str); + + // Recheck the adjusted path + ret = isRegularFile(sysfs_path, ®_file); + if (ret != 0 || !reg_file) { + ss << __PRETTY_FUNCTION__ + << " | Adjusted file path also does not exist - SYSFS file (" + << sysfs_path + << ") for DevInfoInfoType (" << get_type_string(type) + << "), returning " << std::to_string(ret); + LOG_ERROR(ss); + return ret; + } + } + } + if (ret != 0) { ss << __PRETTY_FUNCTION__ << " | Issue: File did not exist - SYSFS file (" << sysfs_path @@ -777,6 +810,7 @@ int Device::openSysfsFileStream(DevInfoTypes type, T *fs, const char *str) { LOG_ERROR(ss); return ret; } + if (!reg_file) { ss << __PRETTY_FUNCTION__ << " | Issue: File is not a regular file - SYSFS file (" @@ -792,7 +826,7 @@ int Device::openSysfsFileStream(DevInfoTypes type, T *fs, const char *str) { if (!fs->is_open()) { ss << __PRETTY_FUNCTION__ << " | Issue: Could not open - SYSFS file (" << sysfs_path << ") for " - << "DevInfoInfoType (" << get_type_string(type) << "), " + << "DevInfoTypes (" << get_type_string(type) << "), " << ", returning " << std::to_string(errno) << " (" << std::strerror(errno) << ")"; LOG_ERROR(ss); @@ -801,7 +835,7 @@ int Device::openSysfsFileStream(DevInfoTypes type, T *fs, const char *str) { ss << __PRETTY_FUNCTION__ << " | Successfully opened SYSFS file (" << sysfs_path - << ") for DevInfoInfoType (" << get_type_string(type) + << ") for DevInfoTypes (" << get_type_string(type) << ")"; LOG_INFO(ss); return 0; diff --git a/projects/amdsmi/src/amd_smi/amd_smi_utils.cc b/projects/amdsmi/src/amd_smi/amd_smi_utils.cc index fa9f809d95..c1f42ebf8d 100644 --- a/projects/amdsmi/src/amd_smi/amd_smi_utils.cc +++ b/projects/amdsmi/src/amd_smi/amd_smi_utils.cc @@ -503,7 +503,12 @@ amdsmi_status_t smi_amdgpu_get_ecc_error_count(amd::smi::AMDSmiGPUDevice* device std::ifstream f(fullpath.c_str()); if (f.fail()) { - return AMDSMI_STATUS_NOT_SUPPORTED; + //fall back to aca file + fullpath = "/sys/class/drm/" + device->get_gpu_path() + std::string("/device/ras/aca_umc"); + f.open(fullpath.c_str()); + if (f.fail()) { + return AMDSMI_STATUS_NOT_SUPPORTED; + } } std::string line;