From 3e2132d9a57962d2a60676568059bac76ea73275 Mon Sep 17 00:00:00 2001 From: ivan-boikov Date: Sun, 22 Dec 2024 16:39:10 +0100 Subject: Configuring CPU count --- components/cpu.c | 12 ++++++------ configure | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/components/cpu.c b/components/cpu.c index a78f17a..48e1b60 100644 --- a/components/cpu.c +++ b/components/cpu.c @@ -6,23 +6,23 @@ #include "../slstatus.h" #include "../util.h" +#define CPUS 12 + #if defined(__linux__) const char * cpu_freq(const char *unused) { - char cpu[128]; unsigned int cores = 0; uintmax_t freq, freq_sum = 0; - while (1) { - sprintf(cpu, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cores); - if (pscanf(cpu, "%ju", &freq) != 1) + for (; cores < CPUS; ++cores) { + sprintf(buf, "/sys/devices/system/cpu/cpu%d/cpufreq/scaling_cur_freq", cores); + if (pscanf(buf, "%ju", &freq) != 1) break; freq_sum += freq; - cores++; } - return bprintf("%.1f", freq_sum/1e6/cores); + return bprintf("%.1f", freq_sum/1e6/CPUS); } const char * diff --git a/configure b/configure index d30fc56..2a1a72a 100755 --- a/configure +++ b/configure @@ -38,3 +38,5 @@ if [ -n "$WLAN" ]; then sed -i "/NETSPEED/a\\\\t{ netspeed_rx, \"%7s \", \"$WLAN\"}," config.h sed -i "/NETSPEED/a\\\\t{ wifi_perc, \"[%3s\", \"$WLAN\"}," config.h fi + +sed -i "s/#define CPUS.*/#define CPUS $(nproc)/" components/cpu.c -- cgit v1.2.3