From 5e3b10bf8c8962ca5c9d4e1f1ebcfc30594b3fb3 Mon Sep 17 00:00:00 2001 From: "Arif, Maisam" Date: Thu, 27 Mar 2025 22:14:28 -0500 Subject: [PATCH] [SWDEV-524147] Patch for handling new ras filenames (#34) Signed-off-by: Maisam Arif [ROCm/rocm_smi_lib commit: 847ac53444a85468ad0420460fb5cada3c1dfa9f] --- projects/rocm-smi-lib/src/rocm_smi_device.cc | 38 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/projects/rocm-smi-lib/src/rocm_smi_device.cc b/projects/rocm-smi-lib/src/rocm_smi_device.cc index 578bb8aabc..5f6d9c98dd 100755 --- a/projects/rocm-smi-lib/src/rocm_smi_device.cc +++ b/projects/rocm-smi-lib/src/rocm_smi_device.cc @@ -661,6 +661,17 @@ int Device::openDebugFileStream(DevInfoTypes type, T *fs, const char *str) { return 0; } +// 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_; @@ -680,6 +691,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 @@ -688,6 +721,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 (" @@ -703,7 +737,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); @@ -712,7 +746,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;