this should fix the read bugs

This commit is contained in:
2026-07-21 14:36:35 +02:00
parent 3f0a96ef7f
commit de500dc5e5
2 changed files with 17 additions and 4 deletions

View File

@@ -6,6 +6,8 @@
#include <time.h>
#include <unistd.h>
static uint64_t max_energy_range_uj = 0;
void cpu_detect(struct cpu_sensors_t *t, const char *pci_dev) {
t->module = unknown;
t->num_cores = sysconf(_SC_NPROCESSORS_ONLN);
@@ -18,6 +20,8 @@ void cpu_detect(struct cpu_sensors_t *t, const char *pci_dev) {
return;
}
static char buf[32];
fast_read_num_u64("/sys/class/powercap/intel-rapl:0/", "max_energy_range_uj", buf, &max_energy_range_uj, 1);
t->module = read_file(t->hwmon, "/in1_input", nullptr, 0) ? zenpower : k10temp; // if we can read zenpower file then zenpower. idk if this is reliable, we're trying to avoid just reading the name
applog(LOG_INF, "Detected %d cores, module enum #%d in path %s", t->num_cores, t->module, t->hwmon);
}
@@ -31,13 +35,20 @@ void cpu_update(struct cpu_sensors_t *c) {
static struct energy_t prev;
struct energy_t curr = {};
uint64_t energy_delta;
// read power from intel-rapl? works on amd too, btop uses this trick, seems accurate
// it tracks with "socket power" in hwinfo on windows, its actually the same thing i had in lcdsmartie
clock_gettime(CLOCK_MONOTONIC, &curr.ts);
fast_read_num_u64("/sys/class/powercap/intel-rapl:0/", "energy_uj", buf, &curr.energy, 1);
c->ptotal = (float)(curr.energy - prev.energy) / (float)timespec_diff_us(&curr.ts, &prev.ts);
if (curr.energy >= prev.energy)
energy_delta = curr.energy - prev.energy;
else
energy_delta = (max_energy_range_uj - prev.energy) + curr.energy;
c->ptotal = (float)energy_delta / (float)timespec_diff_us(&curr.ts, &prev.ts);
if (c->ptotal > 500.0f || c->ptotal < 0.0f)
c->ptotal = 0.0f;
else