Hi,
thanks for your patch!
What do you all think of adding this as a patch to the wiki?
Or is this rather something that more people wish of being included into
the codebase?
Cheers!
Aaron
On 20-11-11 Wed, Platon Ryzhikov wrote:
This is especially useful for ARM SoCs with different cores
---
components/cpu.c | 27 +++++++++++++++++++++------
config.def.h | 4 +++-
2 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/components/cpu.c b/components/cpu.c
index 9e28003..c326297 100644
--- a/components/cpu.c
+++ b/components/cpu.c
@@ -7,16 +7,31 @@
#if defined(__linux__)
const char *
- cpu_freq(void)
+ cpu_freq(const char *range)
{
- uintmax_t freq;
-
- /* in kHz */
- if (pscanf("/sys/devices/system/cpu/cpu0/cpufreq/"
- "scaling_cur_freq", "%ju", &freq) != 1) {
+ uintmax_t freq, sum_freq;
+ static unsigned int i, cpu0, ncpus;
+
+ sum_freq = 0;
+ /* define first cpu in cluster and their number */
+ if (!range) {
+ cpu0 = 0;
+ ncpus = 1;
+ } else if (sscanf(range, "%u %u", &cpu0, &ncpus) != 2) {
return NULL;
}
+ for (i = cpu0; i < cpu0 + ncpus; i += 1) {
+ /* in kHz */
+ if
(pscanf(bprintf("/sys/devices/system/cpu/cpu%d/cpufreq/"
+ "scaling_cur_freq", i), "%ju", &freq) != 1) {
+ return NULL;
+ }
+ sum_freq += freq;
+ }
+
+ freq = (double)sum_freq/(double)ncpus;
+
return fmt_human(freq * 1000, 1000);
}
diff --git a/config.def.h b/config.def.h
index e06be66..6554bb3 100644
--- a/config.def.h
+++ b/config.def.h
@@ -19,7 +19,9 @@ static const char unknown_str[] = "n/a";
* battery_remaining battery remaining HH:MM battery name (BAT0)
* NULL on OpenBSD/FreeBSD
* cpu_perc cpu usage in percent NULL
- * cpu_freq cpu frequency in MHz NULL
+ * cpu_freq cpu frequency in MHz string "first_cpu ncpus"
+ * "0 2" means cpu0+cpu1
+ * NULL on OpenBSD/FreeBSD
* datetime date and time format string (%F %T)
* disk_free free disk space in GB mountpoint path (/)
* disk_perc disk usage in percent mountpoint path (/)
--
2.29.2
--
Web: https://drkhsh.at/ or http://drkhsh5rv6pnahas.onion/
Gopher: gopher://drkhsh.at or gopher://drkhsh5rv6pnahas.onion
GPG: 0x7A65E38D55BE96FE
Fingerprint: 4688 907C 8720 3318 0D9F AFDE 7A65 E38D 55BE 96FE