From 4506e0cf4e4eba78d7685a4314a6882878cc9b66 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 22 Oct 2009 11:18:51 +0200 Subject: Support for multiple CPU cores --- statusbar.c | 67 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/statusbar.c b/statusbar.c index ba36dc8..81e37bf 100644 --- a/statusbar.c +++ b/statusbar.c @@ -3,19 +3,21 @@ * * Needs libacpi-dev and libcpufreq-dev * - * Copyright (c) 2007 T. Klauser + * Copyright (c) 2007-2009 T. Klauser */ #define _GNU_SOURCE #include #include +#include #include + #include #include #include -#define DATE_STR "%a %Y-%m-%d %H:%M" +#define DATE_STR "%Y-%m-%d %H:%M" #define HOUR 3600 /* sec per hour */ #define MINUTE 60 /* sec per min */ #define LOADS_SCALE 65536.0 @@ -26,8 +28,7 @@ int main(int argc, char **argv) struct tm tim; char str[25]; int temp; - unsigned long freq, tmp_freq; - long up, uph, upm; + long i, n_cpu, up, uph, upm; struct sysinfo info; global_t g; @@ -55,6 +56,7 @@ int main(int argc, char **argv) else printf("n/a%% | "); + /* TODO: Use sysfs! */ /* 3) Temperature */ temp = g.temperature; if (temp < 0 || temp == NOT_SUPPORTED) @@ -62,33 +64,38 @@ int main(int argc, char **argv) else printf("%d C | ", temp); - /* 4) Current CPU frequency */ - freq = cpufreq_get_freq_kernel(0); - if (freq) { - /* Taken from cpufrequtils */ - if (freq > 1000000) { - tmp_freq = freq % 10000; - if (tmp_freq >= 5000) - freq += 10000; - printf("%u.%02u G", ((unsigned int) freq / 1000000), - ((unsigned int) (freq % 1000000) / 10000)); - } else if (freq > 100000) { - tmp_freq = freq % 1000; - if (tmp_freq >= 500) - freq += 1000; - printf("%u M", ((unsigned int) freq / 1000)); - } else if (freq > 1000) { - tmp_freq = freq % 100; - if (tmp_freq >= 50) - freq += 100; - printf("%u.%01u M", ((unsigned int) freq / 1000), - ((unsigned int) (freq % 1000) / 100)); - } else - printf("%lu k", freq); + /* 4) Current CPU frequency for each core */ + n_cpu = sysconf(_SC_NPROCESSORS_CONF); + for (i = 0; i < n_cpu; i++) { + unsigned long freq = cpufreq_get_freq_kernel(i); - printf("Hz | "); - } else - printf("n/a | "); + if (freq) { + unsigned long tmp_freq; + /* Taken from cpufrequtils */ + if (freq > 1000000) { + tmp_freq = freq % 10000; + if (tmp_freq >= 5000) + freq += 10000; + printf("%u.%02u G", ((unsigned int) freq / 1000000), + ((unsigned int) (freq % 1000000) / 10000)); + } else if (freq > 100000) { + tmp_freq = freq % 1000; + if (tmp_freq >= 500) + freq += 1000; + printf("%u M", ((unsigned int) freq / 1000)); + } else if (freq > 1000) { + tmp_freq = freq % 100; + if (tmp_freq >= 50) + freq += 100; + printf("%u.%01u M", ((unsigned int) freq / 1000), + ((unsigned int) (freq % 1000) / 100)); + } else + printf("%lu k", freq); + + printf("Hz | "); + } else + printf("n/a | "); + } /* 5) Uptime and load average */ if (sysinfo(&info) == 0) { -- cgit v1.2.3-54-g00ecf