This commit is contained in:
Drath
2025-10-23 13:04:01 +02:00
3 changed files with 14 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
#ifndef CPU_HPP
#define CPU_HPP
#include <chrono>
#include <cstdint>
#include <filesystem>
#include <log.hpp>
@@ -34,4 +35,4 @@ void update(cpuSensors* g);
} // namespace cpu
#endif
#endif

View File

@@ -65,7 +65,7 @@ void hassThread(std::stop_token st, Sensors* s) {
void sensorsThread(std::stop_token st, Sensors* s) {
log(LOG::INF, "Thread", "Starting sensors_thread, pid {}, poll interval {} ms", gettid(), LCD_INTERVAL_MS);
cpu::detectHwmon(&s->cpu, "0000:00:18.3");
gpu::detectHwmon(&s->gpu, "0000:0a:00.0");
gpu::detectHwmon(&s->gpu, "0000:0b:00.0");
sys::detectHwmon(&s->sys, "nct6775.656");
while (!st.stop_requested()) {
@@ -116,6 +116,7 @@ void displayThread(std::stop_token st, Sensors* s) {
cpu_fan = cpu_fan >> 1; // fast divide by 2
// write to display buffer
lcd.clearBuf();
lcd.writeBuf(0, 0, pad(s->td.date, 11, true) + " " + s->td.time + lcd.bar(7, s->gpu.usage_core / 100.0));
lcd.writeBuf(0, 26, pNum(s->avg[0], s->avg[0] > 10 ? 1 : 2));
lcd.writeBuf(0, 31, pNum(s->avg[1], s->avg[1] > 10 ? 1 : 2));
@@ -174,4 +175,4 @@ int main(int argc, char* argv[]) {
delete pSensors;
return 0;
}
}

View File

@@ -17,6 +17,8 @@ void detectHwmon(cpuSensors* target, std::string pci) {
}
void update(cpuSensors* c) {
static std::chrono::time_point<std::chrono::steady_clock> previous_ts;
static uint64_t previous_usage = 0;
// commented out unused values so its faster
if (c->hwmon == "") return; // break if no module
if (c->zenpower) {
@@ -31,6 +33,12 @@ void update(cpuSensors* c) {
} else {
c->tctl = std::stoi(readFile(c->hwmon + "/temp1_input", 2));
c->tccd1 = std::stoi(readFile(c->hwmon + "/temp3_input", 2));
// read power from intel-rapl? works on amd too, btop uses this trick, seems accurate
auto current_ts = std::chrono::steady_clock::now();
auto current_usage = std::stoul(readFile("/sys/class/powercap/intel-rapl:0/energy_uj", 24));
c->ptotal = (float)(current_usage - previous_usage) / (float)(std::chrono::duration_cast<std::chrono::microseconds>(current_ts - previous_ts).count());
previous_ts = current_ts;
previous_usage = current_usage;
}
// lots of reads but still faster than reading /proc/cpuinfo
@@ -42,4 +50,4 @@ void update(cpuSensors* c) {
c->avg_freq /= N_CPU;
}
} // namespace cpu
} // namespace cpu