diff options
| author | ivan-boikov <ik.boikov.public@protonmail.com> | 2024-12-22 16:39:10 +0100 |
|---|---|---|
| committer | ivan-boikov <ik.boikov.public@protonmail.com> | 2024-12-22 16:39:10 +0100 |
| commit | 3e2132d9a57962d2a60676568059bac76ea73275 (patch) | |
| tree | ab524bed9a3758eb1972801489859a71684a74af | |
| parent | e4b38bac467d969e92a0e9609ea6f5761ce1b66e (diff) | |
Configuring CPU count
| -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 |
