From 870c8a298714fbee30f7557268e4e31c42178cf4 Mon Sep 17 00:00:00 2001 From: Drath Date: Fri, 2 Jan 2026 19:55:02 +0100 Subject: [PATCH] use numcores --- include/cpu.hpp | 2 -- src/cpu.cpp | 8 +++++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/cpu.hpp b/include/cpu.hpp index cf5245f..1e7fd32 100644 --- a/include/cpu.hpp +++ b/include/cpu.hpp @@ -4,8 +4,6 @@ #include #include -#define N_CPU 16 - namespace cpu { enum Module : uint8_t { unknown, diff --git a/src/cpu.cpp b/src/cpu.cpp index cde5597..a5598ed 100644 --- a/src/cpu.cpp +++ b/src/cpu.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace cpu { @@ -19,7 +20,8 @@ void detectHwmon(cpuSensors* target, const std::string& pci) { } target->module = utils::fileExists(target->hwmon + "/in1_input") ? zenpower : k10temp; // idk if this is reliable, we're trying to avoid just reading the name - applog(LOG::INF, "Detected module no. {} in path \"{}\"", target->module ? "zenpower" : "k10temp", target->hwmon); + target->num_cores = std::thread::hardware_concurrency(); + applog(LOG::INF, "Detected {} cores, module no. {} in path \"{}\"", target->num_cores, static_cast(target->module), target->hwmon); } void update(cpuSensors* c) { @@ -41,12 +43,12 @@ void update(cpuSensors* c) { // lots of reads but still faster than reading /proc/cpuinfo c->avg_freq = 0; - for (uint8_t i = 0; i < N_CPU; i++) { + for (uint8_t i = 0; i < c->num_cores; i++) { uint32_t t = 0; utils::fastReadNum<1000>("/sys/devices/system/cpu/cpu" + std::to_string(i) + "/cpufreq/cpuinfo_avg_freq", buf, t); c->avg_freq += t; } - c->avg_freq /= N_CPU; + c->avg_freq /= c->num_cores; // commented out unused values so its faster if (c->module == zenpower) {