Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ee9e138

Browse files
committedFeb 17, 2018
Add power support for amdsysfs
1 parent 7878635 commit ee9e138

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed
 

‎libethcore/Farm.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,9 @@ class Farm: public FarmFace
281281
if (hwInfo.deviceType == HwMonitorInfoType::AMD && sysfsh) {
282282
wrap_amdsysfs_get_tempC(sysfsh, hwInfo.deviceIndex, &tempC);
283283
wrap_amdsysfs_get_fanpcnt(sysfsh, hwInfo.deviceIndex, &fanpcnt);
284-
//TODO
285-
//if(power) {
286-
//wrap_amdsysfs_get_power_usage(sysfsh, hwInfo.deviceIndex, &powerW);
287-
//}
284+
if(power) {
285+
wrap_amdsysfs_get_power_usage(sysfsh, hwInfo.deviceIndex, &powerW);
286+
}
288287
}
289288
#endif
290289
}

‎libhwmon/wrapamdsysfs.cpp

+30
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <algorithm>
1616
#include <fstream>
1717
#include <sys/types.h>
18+
#include <regex>
1819
#if defined(__linux)
1920
#include <dirent.h>
2021
#endif
@@ -207,4 +208,33 @@ int wrap_amdsysfs_get_fanpcnt(wrap_amdsysfs_handle *sysfsh, int index, unsigned
207208

208209
*fanpcnt = double(pwm - pwmMin) / double(pwmMax - pwmMin) * 100.0;
209210
return 0;
211+
}
212+
213+
int wrap_amdsysfs_get_power_usage(wrap_amdsysfs_handle *sysfsh, int index, unsigned int *milliwatts)
214+
{
215+
int gpuindex = sysfsh->card_sysfs_device_id[index];
216+
if (gpuindex < 0 || index >= sysfsh->sysfs_gpucount)
217+
return -1;
218+
219+
char dbuf[120];
220+
snprintf(dbuf, 120, "/sys/kernel/debug/dri/%u/amdgpu_pm_info", gpuindex);
221+
222+
std::ifstream ifs(dbuf, std::ios::binary);
223+
std::string line;
224+
225+
while (std::getline(ifs, line))
226+
{
227+
std::smatch sm;
228+
std::regex regex(R"(([\d|\.]+) W \(average GPU\))");
229+
if (std::regex_search(line, sm, regex)) {
230+
if (sm.size() == 2) {
231+
double watt = atof(sm.str(1).c_str());
232+
*milliwatts = (unsigned int)(watt * 1000);
233+
return 0;
234+
}
235+
}
236+
237+
}
238+
239+
return -1;
210240
}

‎libhwmon/wrapamdsysfs.h

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ int wrap_amdsysfs_get_tempC(wrap_amdsysfs_handle *sysfsh, int index, unsigned in
2121

2222
int wrap_amdsysfs_get_fanpcnt(wrap_amdsysfs_handle *sysfsh, int index, unsigned int *fanpcnt);
2323

24+
int wrap_amdsysfs_get_power_usage(wrap_amdsysfs_handle *sysfsh, int index, unsigned int *milliwatts);

0 commit comments

Comments
 (0)
This repository has been archived.