yuge overhaul, threads, hass, rewrote display, hwmons, bunc of shit
This commit is contained in:
58
src/gpu.cpp
58
src/gpu.cpp
@@ -1,9 +1,4 @@
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <gpu.hpp>
|
||||
#include <print>
|
||||
#include <string>
|
||||
#include <utils.hpp>
|
||||
|
||||
struct GpuMetrics_v1_1_t {
|
||||
uint16_t temperature_edge;
|
||||
@@ -84,6 +79,12 @@ struct GpuMetrics_v1_3_t {
|
||||
uint8_t padding1;
|
||||
};
|
||||
|
||||
std::string detectGpuHwmon(std::string pci) {
|
||||
std::string path = getFirstDir("/sys/bus/pci/devices/" + pci + "/hwmon");
|
||||
std::println("[GpuHwmon] Detected path \"{}\"", path);
|
||||
return path;
|
||||
}
|
||||
|
||||
GpuMetricsHeader_t getGpuMetricsHeader(std::string path) {
|
||||
GpuMetricsHeader_t header;
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
@@ -111,7 +112,7 @@ auto getGpuMetrics(GpuMetricsHeader_t h, std::string path) {
|
||||
f.read(reinterpret_cast<char *>(&metrics), sizeof(metrics));
|
||||
f.close();
|
||||
}
|
||||
} break;
|
||||
} break;
|
||||
}
|
||||
|
||||
return metrics;
|
||||
@@ -123,10 +124,10 @@ gpu_t getGpu(GpuMetricsHeader_t header, std::string hw) {
|
||||
uint8_t hwmon = 3;
|
||||
|
||||
// these are always read from fs
|
||||
gpu.fan_speed = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/fan1_input"));
|
||||
gpu.vcore = std::stod(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/in0_input")) / 1000.0;
|
||||
gpu.power_cap = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/power1_cap", 6));
|
||||
gpu.power_max = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/power1_cap_max", 6));
|
||||
gpu.fan_speed = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon) + "/fan1_input"));
|
||||
gpu.vcore = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon) + "/in0_input")) / 1000.0;
|
||||
gpu.power_cap = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon) + "/power1_cap", 3));
|
||||
gpu.power_max = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon) + "/power1_cap_max", 3));
|
||||
// gpu.fan_pwm = std::stoi(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/pwm1")); // not super useful
|
||||
gpu.vram_used = std::stoul(readFile(hw + "/mem_info_vram_used"));
|
||||
gpu.vram_total = std::stoul(readFile(hw + "/mem_info_vram_total"));
|
||||
@@ -148,16 +149,41 @@ gpu_t getGpu(GpuMetricsHeader_t header, std::string hw) {
|
||||
gpu.mem_vrm_temp = metrics.temperature_vrmem;
|
||||
gpu.power_avg = metrics.average_socket_power;
|
||||
} else {
|
||||
gpu.core_clock = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/freq1_input", 6));
|
||||
gpu.mem_clock = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/freq2_input", 6));
|
||||
gpu.vcore = std::stod(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/in0_input")) / 1000.0;
|
||||
gpu.power_avg = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/power1_input", 6));
|
||||
gpu.edge_temp = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/temp1_input", 3));
|
||||
gpu.core_clock = std::stoll(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon) + "/freq1_input", 16)) / 1000000;
|
||||
gpu.mem_clock = std::stoll(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon) + "/freq2_input", 16)) / 1000000;
|
||||
gpu.vcore = std::stod(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon) + "/in0_input", 8)) / 1000.0;
|
||||
gpu.power_avg = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon) + "/power1_input", 3));
|
||||
gpu.edge_temp = std::stol(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon) + "/temp1_input", 2));
|
||||
gpu.core_usage = std::stoi(readFile(hw + "/gpu_busy_percent"));
|
||||
}
|
||||
|
||||
if(gpu.fan_speed > 9999)
|
||||
if (gpu.fan_speed > 9999)
|
||||
gpu.fan_speed = 9999;
|
||||
|
||||
return gpu;
|
||||
}
|
||||
|
||||
gpu_t getGpu(std::string hwmon) {
|
||||
gpu_t gpu;
|
||||
|
||||
// these are always read from fs
|
||||
gpu.fan_speed = std::stol(readFile(hwmon + "/fan1_input", 4));
|
||||
gpu.vcore = std::stol(readFile(hwmon + "/in0_input", 4)) / 1000.0;
|
||||
gpu.power_cap = std::stol(readFile(hwmon + "/power1_cap", 16)) / 1000000;
|
||||
// gpu.power_max = std::stol(readFile(hwmon + "/power1_cap_max", 16)) / 1000000;
|
||||
// gpu.fan_pwm = std::stoi(readFile(hw + "/hwmon/hwmon" + std::to_string(hwmon)+ "/pwm1")); // not super useful
|
||||
gpu.vram_used = std::stoul(readFile(hwmon + "/../../mem_info_vram_used", 16));
|
||||
// gpu.vram_total = std::stoul(readFile(hwmon + "/../../mem_info_vram_total", 16));
|
||||
|
||||
// these also exist in gpu_metrics?
|
||||
gpu.core_clock = std::stoll(readFile(hwmon + "/freq1_input", 16)) / 1000000;
|
||||
gpu.mem_clock = std::stoll(readFile(hwmon + "/freq2_input", 16)) / 1000000;
|
||||
gpu.power_avg = std::stol(readFile(hwmon + "/power1_input", 16)) / 1000000;
|
||||
gpu.edge_temp = std::stol(readFile(hwmon + "/temp1_input", 2));
|
||||
gpu.core_usage = std::stoi(readFile(hwmon + "/../../gpu_busy_percent"));
|
||||
|
||||
if (gpu.fan_speed > 9999)
|
||||
gpu.fan_speed = 9999;
|
||||
|
||||
return gpu;
|
||||
}
|
||||
Reference in New Issue
Block a user