Fixed AMD GPU health readings on Linux.

This commit is contained in:
XMRig 2020-06-18 11:16:26 +07:00
parent 1b928e8bf1
commit 416c9eff69
No known key found for this signature in database
GPG Key ID: 446A53638BE94409

View File

@ -36,27 +36,29 @@ bool AdlLib::m_ready = false;
static const std::string kPrefix = "/sys/bus/pci/drivers/amdgpu/";
static inline bool sysfs_is_file(const char *path)
static inline bool sysfs_is_file(const std::string &path)
{
struct stat sb;
return stat(path, &sb) == 0 && ((sb.st_mode & S_IFMT) == S_IFREG);
return stat(path.c_str(), &sb) == 0 && ((sb.st_mode & S_IFMT) == S_IFREG);
}
static inline std::string sysfs_prefix(const PciTopology &topology)
static inline bool sysfs_is_amdgpu(const std::string &path)
{
std::string path = kPrefix + "0000:" + topology.toString().data() + "/hwmon/hwmon";
if (sysfs_is_file((path + "2/name").c_str())) {
return path + "2/";
if (!sysfs_is_file(path)) {
return false;
}
if (sysfs_is_file((path + "3/name").c_str())) {
return path + "3/";
std::ifstream file(path);
if (!file.is_open()) {
return false;
}
return {};
std::string name;
std::getline(file, name);
return name == "amdgpu";
}
@ -74,6 +76,21 @@ uint32_t sysfs_read(const std::string &path)
}
static inline std::string sysfs_prefix(const PciTopology &topology)
{
const std::string path = kPrefix + "0000:" + topology.toString().data() + "/hwmon/hwmon";
for (uint32_t i = 1; i < 10; ++i) {
const std::string prefix = path + std::to_string(i) + "/";
if (sysfs_is_amdgpu(prefix + "name") && sysfs_read(prefix + "freq1_input")) {
return prefix;
}
}
return {};
}
} // namespace xmrig