diff options
| -rw-r--r-- | components/cpu.c | 12 | ||||
| -rwxr-xr-x | 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 * @@ -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 |
