mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-17 08:17:40 +00:00
Fixed AMD GPU health readings on Linux.
This commit is contained in:
parent
1b928e8bf1
commit
416c9eff69
1 changed files with 27 additions and 10 deletions
|
@ -36,27 +36,29 @@ bool AdlLib::m_ready = false;
|
||||||
static const std::string kPrefix = "/sys/bus/pci/drivers/amdgpu/";
|
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;
|
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)) {
|
||||||
|
return false;
|
||||||
if (sysfs_is_file((path + "2/name").c_str())) {
|
|
||||||
return path + "2/";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sysfs_is_file((path + "3/name").c_str())) {
|
std::ifstream file(path);
|
||||||
return path + "3/";
|
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
|
} // namespace xmrig
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue