Skip to content

Commit d9e312f

Browse files
17314642flightlessmango
authored andcommitted
gpu_fdinfo: fix power usage calculation
since intel hwmon uses joules which equals 1 watt/s we need to adjust for that, because we poll every 500ms. Simple example: If we poll every 1000ms, then power usage shown is 200W (correct) If we poll every 500ms, then power usage shows is 100W (wrong)
1 parent 24daceb commit d9e312f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/gpu_fdinfo.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ float GPU_fdinfo::get_power_usage() {
157157

158158
energy_input = std::stoull(energy_input_str);
159159

160-
return energy_input / 1'000'000;
160+
return (float)energy_input / 1'000'000;
161161
}
162162

163163
void GPU_fdinfo::get_load() {
@@ -175,7 +175,9 @@ void GPU_fdinfo::get_load() {
175175
if (gpu_time_now > previous_gpu_time) {
176176
float time_since_last = now - previous_time;
177177
float gpu_since_last = gpu_time_now - previous_gpu_time;
178-
float power_usage_since_last = power_usage_now - previous_power_usage;
178+
float power_usage_since_last =
179+
(power_usage_now - previous_power_usage) /
180+
((float)METRICS_UPDATE_PERIOD_MS / 1000);
179181

180182
auto result = int((gpu_since_last / time_since_last) * 100);
181183
if (result > 100)
@@ -190,6 +192,8 @@ void GPU_fdinfo::get_load() {
190192
previous_power_usage = power_usage_now;
191193
}
192194

193-
std::this_thread::sleep_for(std::chrono::milliseconds(METRICS_UPDATE_PERIOD_MS));
195+
std::this_thread::sleep_for(
196+
std::chrono::milliseconds(METRICS_UPDATE_PERIOD_MS)
197+
);
194198
}
195199
}

0 commit comments

Comments
 (0)