use numcores

This commit is contained in:
2026-01-02 19:55:02 +01:00
parent 355e8d6dac
commit 870c8a2987
2 changed files with 5 additions and 5 deletions

View File

@@ -4,8 +4,6 @@
#include <cstdint>
#include <string>
#define N_CPU 16
namespace cpu {
enum Module : uint8_t { unknown,

View File

@@ -4,6 +4,7 @@
#include <cstdint>
#include <log.hpp>
#include <string>
#include <thread>
#include <utils.hpp>
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<uint8_t>(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) {