add cpu clock

This commit is contained in:
Drath
2025-07-03 14:46:42 +02:00
parent f89e72d733
commit ada9d22713
2 changed files with 15 additions and 5 deletions

View File

@@ -21,6 +21,7 @@
#define LCD_INTERVAL_MS 500
#define LCD_CONTRAST 215
#define FILL_CHAR ' '
#define N_CPU 16
struct mem_usage_t {
uint64_t free;
@@ -127,21 +128,29 @@ auto getCpuTemp(std::string hw) {
double ptotal = 0.0;
double vcore = 0.0;
double vsoc = 0.0;
uint32_t avg_freq = 0;
} cpu;
// commented out unused values so its faster
if (readFile(hw + "/name") == "zenpower") {
cpu.tdie = (double)(std::stoul(readFile(hw + "/temp1_input")) / 1000.0);
// cpu.tdie = (double)(std::stoul(readFile(hw + "/temp1_input")) / 1000.0);
cpu.tctl = (double)(std::stoul(readFile(hw + "/temp2_input")) / 1000.0);
cpu.tccd1 = (double)(std::stoul(readFile(hw + "/temp3_input")) / 1000.0);
cpu.pcore = (double)(std::stoul(readFile(hw + "/power1_input")) / 1000000.0);
cpu.psoc = (double)(std::stoul(readFile(hw + "/power2_input")) / 1000000.0);
cpu.ptotal = cpu.pcore + cpu.psoc;
cpu.vcore = (double)(std::stoul(readFile(hw + "/in1_input")) / 1000.0);
cpu.vsoc = (double)(std::stoul(readFile(hw + "/in2_input")) / 1000.0);
// cpu.vsoc = (double)(std::stoul(readFile(hw + "/in2_input")) / 1000.0);
} else {
cpu.tctl = (double)(std::stoul(readFile(hw + "/temp1_input")) / 1000.0);
cpu.tccd1 = (double)(std::stoul(readFile(hw + "/temp3_input")) / 1000.0);
}
// lots of reads but still faster than reading /proc/cpuinfo
for(uint8_t i = 0; i < N_CPU; i++)
cpu.avg_freq += (long)(std::stol(readFile("/sys/devices/system/cpu/cpu" + std::to_string(i) + "/cpufreq/cpuinfo_avg_freq", 3)));
cpu.avg_freq /= N_CPU;
return cpu;
}
@@ -208,8 +217,9 @@ int main(int argc, char *argv[]) {
lines[2] += pad(pNum(gpu.fan_speed) + "R", 5);
lines[2] += pad(std::to_string(gpu.power_avg) + "/" + std::to_string(gpu.power_cap) + "W", 9);
lines[3] = pad(pNum(cpu.vcore, 3) + "V", 6, true);
lines[3] += fill(15);
lines[3] = pad(pNum(cpu.vcore, 3) + "V", 7, true);
lines[3] += std::to_string(cpu.avg_freq) + "MHz";
lines[3] += fill(7);
lines[3] += pad(pNum(gpu.core_clock) + "/" + pNum(gpu.mem_clock) + "MHz ", 13);
lines[3] += pad(pNum(gpu.vcore, 3) + "V", 5);